package com.dragon.mmochat.service;

import java.awt.Color;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.regex.Pattern;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

import com.dragon.mmochat.MmochatConstant;
import com.dragon.mmochat.MmochatMain;
import com.dragon.mmochat.message.MmochatBackToOldServer;
import com.dragon.mmochat.message.Mmochat_1_13C;
import com.dragon.mmochat.message.Mmochat_1_14C;
import com.dragon.mmochat.message.Mmochat_1_15C;
import com.dragon.mmochat.message.Mmochat_1_1C;
import com.dragon.mmochat.message.Mmochat_1_1S;
import com.dragon.mmochat.message.Mmochat_1_20S;
import com.dragon.mmochat.message.Mmochat_1_21S;
import com.dragon.mmochat.message.Mmochat_1_22C;
import com.dragon.mmochat.message.Mmochat_1_23S;
import com.dragon.mmochat.message.Mmochat_1_24C;
import com.dragon.mmochat.message.Mmochat_1_30C;
import com.dragon.mmochat.message.Mmochat_1_31S;
import com.dragon.mmochat.message.Mmochat_1_33C;
import com.dragon.mmochat.message.Mmochat_1_35C;
import com.dragon.mmochat.message.Mmochat_1_7S;
import com.dragon.mmochat.message.Mmochat_4_4S;
import com.dragon.mmochat.message.Mmochat_4_9S;
import com.dragon.mmochat.message.Mmochat_5_10S;
import com.dragon.mmochat.message.Mmochat_5_1S;
import com.dragon.mmochat.message.Mmochat_5_31S;
import com.dragon.mmochat.message.Mmochat_6_23C;
import com.dragon.mmochat.message.Mmochat_6_2S;
import com.dragon.mmochat.message.Mmochat_CheckFontMrpLen;
import com.dragon.mmochat.message.Mmochat_CheckSuggesterInfo;
import com.dragon.mmochat.message.Mmochat_CheckSuggesterInfoRet;
import com.dragon.mmochat.message.Mmochat_EnterOtherServerMap;
import com.dragon.mmochat.message.Mmochat_LeaveGame;
import com.dragon.mmochat.message.Mmochat_1_3C;
import com.dragon.mmochat.message.Mmochat_1_3S;
import com.dragon.mmochat.message.Mmochat_1_4C;
import com.dragon.mmochat.message.Mmochat_1_5C;
import com.dragon.mmochat.message.Mmochat_1_8C;
import com.dragon.mmochat.message.Mmochat_1_9C;
import com.dragon.mmochat.message.Mmochat_3_1S;
import com.dragon.mmochat.message.Mmochat_ClientVersionError;
import com.dragon.mmochat.message.Mmochat_SendCfgCtrl;
import com.dragon.mmochat.message.Mmochat_SendSuggestAward;
import com.dragon.mmochat.message.Mmochat_SetPlayerDstId;
import com.dragon.mmochat.model.MmochatAnnouncement;
import com.dragon.mmochat.model.MmochatChenHao;
import com.dragon.mmochat.model.MmochatDailyActivity;
import com.dragon.mmochat.model.MmochatExtraRandomAward;
import com.dragon.mmochat.model.MmochatLevelHint;
import com.dragon.mmochat.model.MmochatRegisterInfo;
import com.dragon.mmochat.model.MmochatSerial;
import com.dragon.mmochat.model.MmochatTeam;
import com.dragon.mmochat.model.MmochatTempUserInfo;
import com.dragon.mmochat.model.MmochatWuDaoWinWords;
import com.dragon.mmochat.model.activity.MmochatSystemState;
import com.dragon.mmochat.model.attackMode.MmochatAttackModeOfAddBlood;
import com.dragon.mmochat.model.attackMode.MmochatAttackModeOfNormal;
import com.dragon.mmochat.model.attackMode.MmochatAttackModeOfRescueTeamer;
import com.dragon.mmochat.model.attackMode.MmochatAttackModeOfSpecialSkill;
import com.dragon.mmochat.model.battle.MmochatBattle;
import com.dragon.mmochat.model.battle.record.MmochatBattleRecordPlayer;
import com.dragon.mmochat.model.enumType.MmochatActionType;
import com.dragon.mmochat.model.enumType.MmochatBattleModelType;
import com.dragon.mmochat.model.enumType.MmochatBattleState;
import com.dragon.mmochat.model.enumType.MmochatBossLevelType;
import com.dragon.mmochat.model.enumType.MmochatChenHaoType;
import com.dragon.mmochat.model.enumType.MmochatDailyActivityType;
import com.dragon.mmochat.model.enumType.MmochatEquipPlaceType;
import com.dragon.mmochat.model.enumType.MmochatEquipQualityType;
import com.dragon.mmochat.model.enumType.MmochatEquipType;
import com.dragon.mmochat.model.enumType.MmochatEquipVersion;
import com.dragon.mmochat.model.enumType.MmochatFamilyType;
import com.dragon.mmochat.model.enumType.MmochatMaterialType;
import com.dragon.mmochat.model.enumType.MmochatMultiPlayerTeamType;
import com.dragon.mmochat.model.enumType.MmochatObjOwnerState;
import com.dragon.mmochat.model.enumType.MmochatObjectType;
import com.dragon.mmochat.model.enumType.MmochatPayLotteryState;
import com.dragon.mmochat.model.enumType.MmochatPetStateType;
import com.dragon.mmochat.model.enumType.MmochatPropType;
import com.dragon.mmochat.model.enumType.MmochatQickStartType;
import com.dragon.mmochat.model.enumType.MmochatRoleBmpType;
import com.dragon.mmochat.model.enumType.MmochatRoleStateType;
import com.dragon.mmochat.model.enumType.MmochatRoleType;
import com.dragon.mmochat.model.enumType.MmochatServerType;
import com.dragon.mmochat.model.enumType.MmochatShowRoleSet;
import com.dragon.mmochat.model.enumType.MmochatSmallMoneyCostType;
import com.dragon.mmochat.model.enumType.MmochatStorePwdState;
import com.dragon.mmochat.model.enumType.MmochatSuperMachineType;
import com.dragon.mmochat.model.enumType.MmochatTaskStateType;
import com.dragon.mmochat.model.enumType.MmochatTaskType;
import com.dragon.mmochat.model.enumType.MmochatTeamStateType;
import com.dragon.mmochat.model.kefu.MmochatKefuQuestion;
import com.dragon.mmochat.model.map.MmochatMap;
import com.dragon.mmochat.model.map.MmochatMapGuider;
import com.dragon.mmochat.model.map.MmochatMapGuiderData;
import com.dragon.mmochat.model.map.MmochatMapTransPoint;
import com.dragon.mmochat.model.object.MmochatCommonObject;
import com.dragon.mmochat.model.object.MmochatEquip;
import com.dragon.mmochat.model.object.MmochatMaterial;
import com.dragon.mmochat.model.object.MmochatPackageGrid;
import com.dragon.mmochat.model.object.MmochatProp;
import com.dragon.mmochat.model.object.MmochatPropEffect;
import com.dragon.mmochat.model.object.MmochatSuperMachine;
import com.dragon.mmochat.model.role.MmochatFriend;
import com.dragon.mmochat.model.role.MmochatMonsterFactory;
import com.dragon.mmochat.model.role.MmochatNpc;
import com.dragon.mmochat.model.role.MmochatPet;
import com.dragon.mmochat.model.role.MmochatPlayer;
import com.dragon.mmochat.model.role.MmochatSimplePlayer;
import com.dragon.mmochat.model.task.MmochatNpcBattle;
import com.dragon.mmochat.model.task.MmochatTask;
import com.dragon.mmochat.service.MmochatTaskService.doSql;
import com.dragon.mmochat.service.MmochatTaskService.saveSqlAfterTaskAction;
import com.dragon.mmochat.util.CallLocalFuncTlv;
import com.dragon.mmochat.util.CreateKeyEventTlvWin;
import com.dragon.mmochat.util.CreateTlvWin;
import com.dragon.mmochat.util.MmochatUtil;
import com.dragon.mmochat.util.SendBigPackUtil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.skymobi.async.AsyncRunnable;
import com.skymobi.exception.NoConnectionException;
import com.skymobi.exception.SkymobiException;
import com.skymobi.handler.SkymobiHandler;
import com.skymobi.handler.SkymobiHandlerListener;
import com.skymobi.message.SkymobiModuleMessage;
import com.skymobi.message.SkymobiProtocolMessage;
import com.skymobi.message.SkymobiProtocolMessage.UserConnInfo;
import com.skymobi.message.widget.AddDataTLV;
import com.skymobi.message.widget.AddEditBoxTLV;
import com.skymobi.message.widget.ClearDataTLV;
import com.skymobi.message.widget.CloseWinTLV;
import com.skymobi.message.widget.CreateEditBoxTLV;
import com.skymobi.message.widget.CreateMsgBoxTLV;
import com.skymobi.message.widget.CtrlTLVStructureRequest;
import com.skymobi.message.widget.SendDataTLV;
import com.skymobi.message.widget.ShowWaitingMsgBoxTLV;
import com.skymobi.message.widget.TLVStructure;
import com.skymobi.message.widget.WinType;
import com.skymobi.service.SkymobiService;
import com.skymobi.util.Text;

public class MmochatMainService implements SkymobiHandlerListener {
	private static Logger log = LoggerFactory
			.getLogger(MmochatMainService.class);
	public static ScheduledExecutorService checkDeadManThread = Executors
			.newScheduledThreadPool(1);
	public static ScheduledExecutorService checkManLeavingGame = Executors
			.newScheduledThreadPool(1);

	public static ScheduledExecutorService updateSqlAfterLeaveGameThread = Executors
			.newScheduledThreadPool(1);

	// 需要保存退出游戏后数据库的角色队列:roleId-->角色
	public static Map<Integer, MmochatPlayer> needToSaveLeaveGameSqlPlayerMap = new ConcurrentHashMap<Integer, MmochatPlayer>();
	// public static ConcurrentLinkedQueue<MmochatPlayer>
	// needToSaveLeaveGameSqlPlayerQueue = new
	// ConcurrentLinkedQueue<MmochatPlayer>();

	// private static String announcement = null;

	private static SkymobiHandler commonHandler = null;
	// 所有在线玩家：roleId->角色
	public static Map<Integer, MmochatPlayer> players = new ConcurrentHashMap<Integer, MmochatPlayer>();
	// 所有在线玩家：skyId->roleId
	public static Map<Long, Integer> players_skyIdMap = new ConcurrentHashMap<Long, Integer>();

	// 短暂离线玩家: roleId->角色
	public static Map<Integer, MmochatPlayer> offlinePlayers = new ConcurrentHashMap<Integer, MmochatPlayer>();
	// 短暂离线玩家：skyId->roleId
	public static Map<Long, Integer> offlinePlayers_skyIdMap = new ConcurrentHashMap<Long, Integer>();

	// 所有在线玩家的昵称->roleId映射
	public static Map<String, Integer> nameMap = new ConcurrentHashMap<String, Integer>();

	// 等级提示:level->MmochatLevelHint
	public static List<MmochatLevelHint> levelHints = new ArrayList<MmochatLevelHint>();

	// 注册信息
	public static Map<Long, MmochatRegisterInfo> registerBuffer = new ConcurrentHashMap<Long, MmochatRegisterInfo>();

	// 游客：手机编号-->临时roleId；重启后清空重置
	public static Map<String, Integer> guestMap = new ConcurrentHashMap<String, Integer>();

	// cfg控制文件
	// public static byte[] cfgBuffer = null;

	// 下载控制文件的人数
	// public static int cfgRoleNum = 0;

	private static Object multiServerLoginLock = new Object();

	// 战斗模板
	private static Map<MmochatBattleModelType, MmochatNpcBattle> battleModels = new ConcurrentHashMap<MmochatBattleModelType, MmochatNpcBattle>();

	// 曾经可能使用加速软件的名单(可能当前未使用):roleId-->检测到每分钟收发次数
	public static Map<Integer, Integer> speedUpRoles = new ConcurrentHashMap<Integer, Integer>();

	public void init() {
		if (!MmochatMain.openMergeServer) {
			System.out.print("MmochatMainService init called!");

			// 检查掉线的玩家线程
			checkDeadManThread.scheduleWithFixedDelay(new CheckDeadMan(), 80,
					30, TimeUnit.SECONDS);

			// 检测玩家真正离线的线程
			checkManLeavingGame.scheduleWithFixedDelay(new CheckManLeaveGame(),
					60, 20, TimeUnit.SECONDS);

			updateSqlAfterLeaveGameThread.scheduleAtFixedRate(
					new saveSqlAfterLeaveGameAction(), 60000, 50,
					TimeUnit.MILLISECONDS);

			// 加载"base/battleModel.xml"文件
			battleModels.clear();
			try {
				File root = new File("base/battleModel");
				File[] files = root.listFiles();
				if (files != null) {
					for (File file : files) {
						if (!file.isFile()) {
							continue;
						}
						DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
								.newInstance();
						DocumentBuilder docBuilder = docBuilderFactory
								.newDocumentBuilder();
						Document doc = docBuilder.parse(file);
						// normalize text redivsentation
						doc.getDocumentElement().normalize();
						NodeList listOfTask = doc
								.getElementsByTagName("battle");
						log.debug("有" + listOfTask.getLength() + "个战斗模板。");

						for (int s = 0; s < listOfTask.getLength(); s++) {
							Node firstTaskNode = listOfTask.item(s);
							if (firstTaskNode.getNodeType() == Node.ELEMENT_NODE) {
								Element firstTaskElement = (Element) firstTaskNode;
								MmochatNpcBattle battle = createNpcBattleFromFile(firstTaskElement);
								// 读取type
								NodeList hintList = firstTaskElement
										.getElementsByTagName("type");
								String hintStr = hintList.item(0)
										.getChildNodes().item(0).getNodeValue()
										.trim();
								MmochatBattleModelType battleType = MmochatBattleModelType
										.valueOf(hintStr);
								battleModels.put(battleType, battle);
							}
						}
					}
				}
			} catch (SAXParseException err) {
				log.debug("** Parsing error" + ", line " + err.getLineNumber()
						+ ", uri " + err.getSystemId());
				log.debug(" " + err.getMessage());
				err.printStackTrace();
				throw new RuntimeException("任务初始化失败,请重启!");
			} catch (SAXException e) {
				Exception x = e.getException();
				((x == null) ? e : x).printStackTrace();
				throw new RuntimeException("任务初始化失败,请重启!");
			} catch (Throwable t) {
				t.printStackTrace();
				throw new RuntimeException("任务初始化失败,请重启!");
			}

			// 加载"base/等级提示.xml"文件
			levelHints.clear();
			try {
				File file = new File("base/levelHint.xml");
				if (file != null) {
					if (file.isFile()) {
						DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
								.newInstance();
						DocumentBuilder docBuilder = docBuilderFactory
								.newDocumentBuilder();
						Document doc = docBuilder.parse(file);
						// normalize text redivsentation
						doc.getDocumentElement().normalize();
						NodeList listOfTask = doc
								.getElementsByTagName("levelHint");
						log.debug("有" + listOfTask.getLength() + "个等级提示。");

						for (int s = 0; s < listOfTask.getLength(); s++) {
							Node firstTaskNode = listOfTask.item(s);
							if (firstTaskNode.getNodeType() == Node.ELEMENT_NODE) {
								Element firstTaskElement = (Element) firstTaskNode;
								MmochatLevelHint hint = new MmochatLevelHint();

								// 读取level
								NodeList levelList = firstTaskElement
										.getElementsByTagName("level");
								String levelStr = levelList.item(0)
										.getChildNodes().item(0).getNodeValue()
										.trim();
								try {
									int level = Integer.parseInt(levelStr);
									hint.setLevel(level);
								} catch (Exception e) {
									e.printStackTrace();
									throw new RuntimeException(
											"base/levelHint.xml中等级有非数字,第"
													+ (s + 1) + "个。");
								}

								// 读取hint
								NodeList hintList = firstTaskElement
										.getElementsByTagName("hint");
								String hintStr = hintList.item(0)
										.getChildNodes().item(0).getNodeValue()
										.trim();
								hint.setHint(hintStr);

								levelHints.add(hint);
							}
						}
					}
				}
			} catch (SAXParseException err) {
				log.debug("** Parsing error" + ", line " + err.getLineNumber()
						+ ", uri " + err.getSystemId());
				log.debug(" " + err.getMessage());
				err.printStackTrace();
				throw new RuntimeException("任务初始化失败,请重启!");
			} catch (SAXException e) {
				Exception x = e.getException();
				((x == null) ? e : x).printStackTrace();
				throw new RuntimeException("任务初始化失败,请重启!");
			} catch (Throwable t) {
				t.printStackTrace();
				throw new RuntimeException("任务初始化失败,请重启!");
			}
		}
	}

	// 平均每2秒最多能执行大约1次，在高峰期，100人同时退出情况下，平均每人3分钟会保存一次数据库
	// 未保存时数据会在内存中，故不影响数据同步
	class saveSqlAfterLeaveGameAction implements Runnable {
		@Override
		public void run() {
			try {
				if (System.currentTimeMillis() < MmochatConstant.startSaveSqlAfterJobTick) {
					return;
				}
				// 选出一个进行保存
				Integer myRoleId = null;
				for (MmochatPlayer member : needToSaveLeaveGameSqlPlayerMap
						.values()) {
					if (member != null) {
						myRoleId = member.getRoleId();
						break;
					}
				}
				MmochatPlayer me = null;
				if (myRoleId != null) {
					me = needToSaveLeaveGameSqlPlayerMap.remove(myRoleId);
				}
				if (me != null) {
					// 为防止死锁等导致一条操作无法结束，每次启动新的线程来执行
					new Thread(new doSql(me)).start();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	class doSql extends Thread {
		MmochatPlayer me = null;

		public doSql(MmochatPlayer m) {
			me = m;
		}

		@SuppressWarnings("deprecation")
		public void run() {
			try {
				if (me != null) {
					// 从其它数据库队列中移除
					try {
						MmochatBattleService.needToSaveBattleSqlPlayerQueue
								.remove(me);
						MmochatTaskService.needToSaveTaskSqlPlayerQueue
								.remove(me);
						MmochatPropService.needToSavePropSqlPlayerQueue
								.remove(me);
					} catch (Exception e1) {
						e1.printStackTrace();
					}

					// 保存数据库
					boolean success = false;
					for (int i = 0; i < 5; i++) {
						try {
							log.debug("角色ID:" + me.getRoleId() + "开始第"
									+ (i + 1) + "次保存");
							MmochatDao.updateRoleLeaveGame(me);
							success = true;
							break;
						} catch (Exception e) {
							// 保存失败
							log.error("角色ID:" + me.getRoleId() + "第" + (i + 1)
									+ "次保存失败");
						}
					}
					if (!success) {
						// 保存失败，重新 放入队列中
						needToSaveLeaveGameSqlPlayerMap.put(me.getRoleId(), me);
						return;
					}

					// 保存数据库后，从内存中移除
					Date now = new Date();
					// 通知好友我下线了
					for (Integer roleId : me.getMyFans().values()) {
						MmochatPlayer friend = players.get(roleId);
						if (friend == null) {
							continue;
						}
						if (friend.getMyDearFriends().get(me.getRoleId()) == null) {
							// 在我离线期间，这位好友将我删出好友了
							me.delFans(roleId);
						} else {
							// 下线消息
							friend.addOffLineFriend(me.getRoleId());
							// 如果对方关注我，则向其发送系统消息
							if (friend.getMyIdols().containsKey(me.getRoleId())) {
								MmochatChatService.sendSystemMsgToPerson(
										friend, "您的好友"
												+ MmochatUtil
														.wrapColor(
																me.getName(),
																Color.white)
												+ "下线了!");
							}
						}
					}

					// TODO:其它下线处理

					// 判断离线时与登陆是否为同一天，如果不是，则增加本月登陆天数次数
					Date loginDate = new Date(me.getLatest_login_time());
					if (now.getYear() == loginDate.getYear()
							&& now.getMonth() == loginDate.getMonth()
							&& now.getDate() == loginDate.getDate()) {
						// 同一天
					} else {
						long interval = now.getTime()
								- me.getLatest_login_time();
						long dayNum = interval / MmochatConstant.MS_PER_DAY;
						dayNum = Math.max(dayNum, 1);
						me.addCur_month_login_day_num((int) dayNum);
					}

					offlinePlayers.remove(me.getRoleId());
					if (!me.isGuest()) {
						offlinePlayers_skyIdMap.remove(me.getSkyId());
					}

					// 统计总在线时长
					MmochatStatisticsService.todayTotalOnlineTime += now
							.getTime()
							- me.getLatest_login_time();

					log.debug(me.getName() + "执行updateRoleLeaveGame操作!");
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	// 加载cfg控制终端程序文件到内存供下载
	// private static void loadTerm() {
	// File file = new File("term");
	// if (file.exists()) {
	// if (file.isFile()) {
	// BufferedInputStream instream;
	// try {
	// instream = new BufferedInputStream(
	// new FileInputStream(file));
	// try {
	// byte[] b = new byte[instream.available()];
	// int len = instream.read(b, 0, b.length);
	// instream.close();
	// if (len != -1) {
	// cfgBuffer = b;
	// System.out.println("load cfgBuffer success!");
	// }
	// } catch (IOException ex) {
	// ex.printStackTrace();
	// }
	// } catch (FileNotFoundException ex) {
	// ex.printStackTrace();
	// }
	// }
	// }
	// }

	// 从配置文件读取battle标签
	public static MmochatNpcBattle createNpcBattleFromFile(Element battleElement) {
		MmochatNpcBattle npcBattle = new MmochatNpcBattle();
		// 读取mustWin
		{
			NodeList nodeList = battleElement.getElementsByTagName("mustWin");
			if (nodeList.getLength() > 0) {
				String str = nodeList.item(0).getChildNodes().item(0)
						.getNodeValue().trim();
				int num = 0;
				try {
					num = Integer.parseInt(str.trim());
				} catch (Exception e) {
					e.printStackTrace();
					throw new RuntimeException("mustWin不是数字");
				}
				if (num == 0) {
					npcBattle.setMustWin(false);
				} else {
					npcBattle.setMustWin(true);
				}
			}
		}

		// 读取主怪
		NodeList bossList = battleElement.getElementsByTagName("主怪");
		if (bossList.getLength() > 0) {
			MmochatMonsterFactory boss = new MmochatMonsterFactory();
			Node bossNode = bossList.item(0);
			if (bossNode.getNodeType() == Node.ELEMENT_NODE) {
				Element bossElement = (Element) bossNode;

				// 读取名字
				NodeList nameList = bossElement.getElementsByTagName("名字");
				String name = nameList.item(0).getChildNodes().item(0)
						.getNodeValue().trim();
				boss.setName(name);
				// 读取图片
				NodeList bmpList = bossElement.getElementsByTagName("图片");
				String bmpStr = bmpList.item(0).getChildNodes().item(0)
						.getNodeValue().trim();
				MmochatRoleBmpType type = MmochatRoleBmpType.valueOf(bmpStr);
				if (type == null) {
					throw new RuntimeException("BOSS的图片非法");
				}
				boss.setBmpType(type);

				// 读取等级类型
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("等级类型");
					String str = nodeList.item(0).getChildNodes().item(0)
							.getNodeValue().trim();
					MmochatBossLevelType levelType = MmochatBossLevelType
							.valueOf(str);
					boss.setLevelType(levelType);
				}
				// 读取等级
				{
					NodeList nodeList = bossElement.getElementsByTagName("等级");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的等级不是数字");
						}
						boss.setLevel(num);
					}
				}
				// 读取技能门派
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("技能门派");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						boss.setFamily(MmochatFamilyType.valueOf(str));
					}
				}
				// 读取道行倍数
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("道行倍数");

					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						double num = 0;
						try {
							num = Double.parseDouble(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的道行倍数不是数字");
						}
						boss.setDaoParam(num);
					}
				}

				// 设置道行
				if (boss.getLevel() >= 0) {
					boss
							.setDao((int) (boss.getDaoParam() * MmochatBattleService
									.getStandardDao(boss.getLevel(), 0)));
				}
				// 读取装备锻造等级
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("装备锻造等级");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的装备锻造等级不是数字");
						}
						boss.setEquipLevel(num);
					}
				}
				// 读取队伍伤害输出人数
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("队伍伤害输出人数");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						double num = 0;
						try {
							num = Double.parseDouble(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的队伍伤害输出人数不是数字");
						}
						boss.setTeamNum(num);
					}
				}
				// 读取消灭回合数
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("消灭回合数");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						double num = 0;
						try {
							num = Double.parseDouble(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的消灭回合数不是数字");
						}
						boss.setKillRound(num);
					}
				}
				// 读取物伤系数
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("物伤系数");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						double num = 0;
						try {
							num = Double.parseDouble(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的物伤系数不是数字");
						}
						boss.setPhysical(num);
					}
				}
				// 读取法伤系数
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("法伤系数");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						double num = 0;
						try {
							num = Double.parseDouble(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的法伤系数不是数字");
						}
						boss.setMagic(num);
					}
				}
				// 读取速度系数
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("速度系数");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的速度系数不是数字");
						}
						boss.setSpeedPointAddType(num);
					}
				}
				// 读取技能目标数
				NodeList targetNumList = bossElement
						.getElementsByTagName("技能目标数");
				if (targetNumList.getLength() > 0) {
					String targetNum = targetNumList.item(0).getChildNodes()
							.item(0).getNodeValue().trim();
					try {
						int num = Integer.parseInt(targetNum.trim());
						boss.setBossMaxSkillTargetNum(num);
					} catch (Exception e) {
						e.printStackTrace();
						throw new RuntimeException("技能目标数不是数字");
					}
				}

				// 读取物理闪避
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("物理闪避");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的物理闪避不是数字");
						}
						boss.setPhysicalAvoid(num);
					}
				}

				// 读取法术闪避
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("法术闪避");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的法术闪避不是数字");
						}
						boss.setMagicAvoid(num);
					}
				}

				// 读取物理暴击
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("物理暴击");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的物理暴击不是数字");
						}
						boss.setPhysicalDeadlyAttack(num);
					}
				}

				// 读取法术暴击
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("法术暴击");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的法术暴击不是数字");
						}
						boss.setMagicDeadlyAttack(num);
					}
				}

				// 读取物理暴击抵抗
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("物理暴击抵抗");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的物理暴击抵抗不是数字");
						}
						boss.setPhysicalDeadlyAttackDefend(num);
					}
				}

				// 读取法术暴击抵抗
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("法术暴击抵抗");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的法术暴击抵抗不是数字");
						}
						boss.setMagicDeadlyAttackDefend(num);
					}
				}

				// 读取物理致命一击
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("物理致命一击");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的物理致命一击不是数字");
						}
						boss.setPhysicalDoubleAttack(num);
					}
				}

				// 读取法术致命一击
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("法术致命一击");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的法术致命一击不是数字");
						}
						boss.setMagicDoubleAttack(num);
					}
				}

				// 读取物理致命抵抗
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("物理致命抵抗");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的物理致命抵抗不是数字");
						}
						boss.setPhysicalDoubleAttackDefend(num);
					}
				}

				// 读取法术致命抵抗
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("法术致命抵抗");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的法术致命抵抗不是数字");
						}
						boss.setMagicDoubleAttackDefend(num);
					}
				}

				// 读取物理破防
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("物理破防");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的物理破防不是数字");
						}
						boss.setPhysicalDefendIgnore(num);
					}
				}

				// 读取法术破防
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("法术破防");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的法术破防不是数字");
						}
						boss.setMagicDefendIgnore(num);
					}
				}

				// 读取封印抵抗
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("封印抵抗");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的封印抵抗不是数字");
						}
						boss.setAntiSeal(num);
					}
				}

				// 读取冰冻抵抗
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("冰冻抵抗");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的冰冻抵抗不是数字");
						}
						boss.setAntiFreeze(num);
					}
				}

				// 读取混乱抵抗
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("混乱抵抗");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的混乱抵抗不是数字");
						}
						boss.setAntiConfuse(num);
					}
				}

				// 读取忽视封印抵抗
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("忽视封印抵抗");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的忽视封印抵抗不是数字");
						}
						boss.setIgnoreAntiSeal(num);
					}
				}

				// 读取忽视冰冻抵抗
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("忽视冰冻抵抗");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的忽视冰冻抵抗不是数字");
						}
						boss.setIgnoreAntiFreeze(num);
					}
				}

				// 读取忽视混乱抵抗
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("忽视混乱抵抗");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的忽视混乱抵抗不是数字");
						}
						boss.setIgnoreAntiConfuse(num);
					}
				}

				// 读取强化封印
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("强化封印");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的强化封印不是数字");
						}
						boss.setStrengthenSeal(num);
					}
				}

				// 读取强化冰冻
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("强化冰冻");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的强化冰冻不是数字");
						}
						boss.setStrengthenFreeze(num);
					}
				}

				// 读取强化混乱
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("强化混乱");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的强化混乱不是数字");
						}
						boss.setStrengthenConfuse(num);
					}
				}

				// 读取物理免疫
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("物理免疫");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的物理免疫不是数字");
						}
						boss.setPhysicalDefendPercent(num);
					}
				}

				// 读取法术免疫
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("法术免疫");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的法术免疫不是数字");
						}
						boss.setMagicDefendPercent(num);
					}
				}

				// 读取抗雷
				{
					NodeList nodeList = bossElement.getElementsByTagName("抗雷");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的抗雷不是数字");
						}
						boss.setAntiGodSkill(num);
					}
				}

				// 读取抗水
				{
					NodeList nodeList = bossElement.getElementsByTagName("抗水");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的抗水不是数字");
						}
						boss.setAntiHumanSkill(num);
					}
				}

				// 读取抗毒
				{
					NodeList nodeList = bossElement.getElementsByTagName("抗毒");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的抗毒不是数字");
						}
						boss.setAntiDevilSkill(num);
					}
				}

				// 读取忽视抗雷
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("忽视抗雷");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的忽视抗雷不是数字");
						}
						boss.setIgnoreAntiGodSkill(num);
					}
				}
				// 读取忽视抗水
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("忽视抗水");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的忽视抗水不是数字");
						}
						boss.setIgnoreAntiHumanSkill(num);
					}
				}

				// 读取忽视抗毒
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("忽视抗毒");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的忽视抗毒不是数字");
						}
						boss.setIgnoreAntiDevilSkill(num);
					}
				}

				// 读取神圣物理伤害
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("神圣物理伤害");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的神圣物理伤害不是数字");
						}
						boss.setSuperPhysicalAttack(num);
					}
				}

				// 读取神圣法术伤害
				{
					NodeList nodeList = bossElement
							.getElementsByTagName("神圣法术伤害");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的神圣法术伤害不是数字");
						}
						boss.setSuperSpritAttack(num);
					}
				}

				// 读取是否能复活
				{
					NodeList nodeList = bossElement.getElementsByTagName("复活");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						if (str.equals("能")) {
							boss.setCanRescure(true);
						} else if (str.equals("不能")) {
							boss.setCanRescure(false);
						} else {
							throw new RuntimeException("BOSS的复活项非法,只能填<能>或<不能>");
						}
					}
				}
				// 读取常规攻击模式
				NodeList normalModeList = bossElement
						.getElementsByTagName("常规攻击");
				if (normalModeList.getLength() > 0) {
					Node normalMode = normalModeList.item(0);
					if (normalMode.getNodeType() == Node.ELEMENT_NODE) {
						MmochatAttackModeOfNormal normalAttackMode = new MmochatAttackModeOfNormal();
						Element normalElement = (Element) normalMode;
						// 读取物攻机率
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("物攻机率");
							if (nodeList.getLength() > 0) {
								String str = nodeList.item(0).getChildNodes()
										.item(0).getNodeValue().trim();
								int num = 0;
								try {
									num = Integer.parseInt(str.trim());
								} catch (Exception e) {
									e.printStackTrace();
									throw new RuntimeException(
											"加载任务时，BOSS的物攻机率不是数字,taskId=");
								}
								normalAttackMode
										.setPhysicalAttackOpportunity(num);
							}
						}
						// 读取法攻机率
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("法攻机率");
							if (nodeList.getLength() > 0) {
								String str = nodeList.item(0).getChildNodes()
										.item(0).getNodeValue().trim();
								int num = 0;
								try {
									num = Integer.parseInt(str.trim());
								} catch (Exception e) {
									e.printStackTrace();
									throw new RuntimeException(
											"加载任务时，BOSS的法攻机率不是数字,taskId=");
								}
								normalAttackMode.setMagicAttackOppotunity(num);
							}
						}
						// 读取障碍技能机率
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("障碍机率");
							if (nodeList.getLength() > 0) {
								String str = nodeList.item(0).getChildNodes()
										.item(0).getNodeValue().trim();
								int num = 0;
								try {
									num = Integer.parseInt(str.trim());
								} catch (Exception e) {
									e.printStackTrace();
									throw new RuntimeException(
											"加载任务时，BOSS的障碍机率不是数字,taskId=");
								}
								normalAttackMode.setLimitOppotunity(num);
							}
						}
						// 读取辅助技能机率
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("辅助机率");
							if (nodeList.getLength() > 0) {
								String str = nodeList.item(0).getChildNodes()
										.item(0).getNodeValue().trim();
								int num = 0;
								try {
									num = Integer.parseInt(str.trim());
								} catch (Exception e) {
									e.printStackTrace();
									throw new RuntimeException(
											"加载任务时，BOSS的辅助机率不是数字,taskId=");
								}
								normalAttackMode.setFuZhuOppotunity(num);
							}
						}
						boss.setAttackMode_normal(normalAttackMode);
					}
				} else {
					throw new RuntimeException("加载任务时，BOSS的常规攻击未设置");
				}

				// 读取特殊技能模式
				NodeList specialSkillModeList = bossElement
						.getElementsByTagName("特殊技能");
				for (int ss = 0; ss < specialSkillModeList.getLength(); ss++) {
					Node normalMode = specialSkillModeList.item(ss);
					if (normalMode.getNodeType() == Node.ELEMENT_NODE) {
						MmochatAttackModeOfSpecialSkill specialSkillMode = new MmochatAttackModeOfSpecialSkill();
						Element normalElement = (Element) normalMode;
						// 读取血量底于多少百分比可能触发
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("血量底于多少百分比可能触发");
							if (nodeList.getLength() > 0) {
								String str = nodeList.item(0).getChildNodes()
										.item(0).getNodeValue().trim();
								int num = 0;
								try {
									num = Integer.parseInt(str.trim());
								} catch (Exception e) {
									e.printStackTrace();
									throw new RuntimeException(
											"加载任务时，BOSS的特殊技能<血量底于多少百分比可能触发>不是数字,taskId=");
								}
								specialSkillMode.setStartBloodPercent(num);
							}
						}
						// 读取触发机率
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("触发机率");
							if (nodeList.getLength() > 0) {
								String str = nodeList.item(0).getChildNodes()
										.item(0).getNodeValue().trim();
								int num = 0;
								try {
									num = Integer.parseInt(str.trim());
								} catch (Exception e) {
									e.printStackTrace();
									throw new RuntimeException(
											"加载任务时，BOSS的特殊技能触发机率不是数字,taskId=");
								}
								specialSkillMode.setOpportunity(num);
							}
						}
						// 读取技能类型
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("技能类型");
							String str = nodeList.item(0).getChildNodes().item(
									0).getNodeValue().trim();
							MmochatActionType actionType = null;
							try {
								actionType = MmochatActionType.valueOf(str);
							} catch (Exception e) {
								e.printStackTrace();
								throw new RuntimeException(
										"加载任务时，BOSS的特殊技能<技能类型>非法,taskId=");
							}
							specialSkillMode.setActionType(actionType);
						}
						// 读取执行时间
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("执行时间");
							String str = nodeList.item(0).getChildNodes().item(
									0).getNodeValue().trim();
							if (str != null && str.equals("下个回合")) {
								specialSkillMode.setNextRound(true);
							}
						}
						// 读取系统提示
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("系统提示");
							String str = nodeList.item(0).getChildNodes().item(
									0).getNodeValue().trim();
							if (str != null) {
								specialSkillMode.setHint(str);
							}
						}
						boss.getAttackModeOfSpecialSkill()
								.add(specialSkillMode);
					}
				}

				// 读取自己补血模式
				NodeList addBloodModeList = bossElement
						.getElementsByTagName("自己补血");
				if (addBloodModeList.getLength() > 0) {
					Node normalMode = addBloodModeList.item(0);
					if (normalMode.getNodeType() == Node.ELEMENT_NODE) {
						MmochatAttackModeOfAddBlood addBloodAttackMode = new MmochatAttackModeOfAddBlood();
						Element normalElement = (Element) normalMode;
						// 读取血量底于多少百分比可能触发
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("血量底于多少百分比可能触发");
							String str = nodeList.item(0).getChildNodes().item(
									0).getNodeValue().trim();
							int num = 0;
							try {
								num = Integer.parseInt(str.trim());
							} catch (Exception e) {
								e.printStackTrace();
								throw new RuntimeException(
										"加载任务时，BOSS的<血量底于多少百分比可能触发>不是数字,taskId=");
							}
							addBloodAttackMode.setTriggerBloodPercent(num);

						}
						// 读取补血机率
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("补血机率");

							String str = nodeList.item(0).getChildNodes().item(
									0).getNodeValue().trim();
							int num = 0;
							try {
								num = Integer.parseInt(str.trim());
							} catch (Exception e) {
								e.printStackTrace();
								throw new RuntimeException(
										"加载任务时，BOSS的补血机率不是数字,taskId=");
							}
							addBloodAttackMode.setAddBloodOpportunity(num);

						}
						// 读取补多少百分比的血
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("补多少百分比的血");
							if (nodeList.getLength() > 0) {
								String str = nodeList.item(0).getChildNodes()
										.item(0).getNodeValue().trim();
								int num = 0;
								try {
									num = Integer.parseInt(str.trim());
								} catch (Exception e) {
									e.printStackTrace();
									throw new RuntimeException(
											"加载任务时，BOSS的<补多少百分比的血>不是数字,taskId=");
								}
								addBloodAttackMode.setAddBloodPercent(num);
							}
						}
						boss.setAttackMode_addBlood(addBloodAttackMode);
					}
				}

				// 读取救助队友模式
				NodeList rescueTeamerModeList = bossElement
						.getElementsByTagName("救活死亡队友");
				if (rescueTeamerModeList.getLength() > 0) {
					Node normalMode = rescueTeamerModeList.item(0);
					if (normalMode.getNodeType() == Node.ELEMENT_NODE) {
						MmochatAttackModeOfRescueTeamer rescueTeamerAttackMode = new MmochatAttackModeOfRescueTeamer();
						Element normalElement = (Element) normalMode;
						// 读取触发机率
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("触发机率");
							String str = nodeList.item(0).getChildNodes().item(
									0).getNodeValue().trim();
							int num = 0;
							try {
								num = Integer.parseInt(str.trim());
							} catch (Exception e) {
								e.printStackTrace();
								throw new RuntimeException(
										"加载任务时，BOSS的救人的<触发机率>不是数字,taskId=");
							}
							rescueTeamerAttackMode.setRescueOpportunity(num);

						}
						// 读取补多少百分比的血
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("补多少百分比的血");

							String str = nodeList.item(0).getChildNodes().item(
									0).getNodeValue().trim();
							int num = 0;
							try {
								num = Integer.parseInt(str.trim());
							} catch (Exception e) {
								e.printStackTrace();
								throw new RuntimeException(
										"加载任务时，BOSS的救人的<补多少百分比的血>不是数字,taskId=");
							}
							rescueTeamerAttackMode.setBloodPercent(num);

						}
						boss.setAttackMode_rescueTeamer(rescueTeamerAttackMode);
					}
				}
			}
			npcBattle.setBoss(boss);
		} else {
			throw new RuntimeException("加载任务时的battle时，没有设置BOSS,taskId=");
		}

		// 读取小怪
		List<MmochatMonsterFactory> smallBoss = new ArrayList<MmochatMonsterFactory>();

		NodeList monsterList = battleElement.getElementsByTagName("小怪");
		for (int s = 0; s < monsterList.getLength(); s++) {
			MmochatMonsterFactory smallMonster = new MmochatMonsterFactory();
			Node monsterNode = monsterList.item(s);
			if (monsterNode.getNodeType() == Node.ELEMENT_NODE) {
				Element smallMonsterElement = (Element) monsterNode;

				// 读取名字
				NodeList nameList = smallMonsterElement
						.getElementsByTagName("名字");
				String name = nameList.item(0).getChildNodes().item(0)
						.getNodeValue().trim();
				smallMonster.setName(name);
				// 读取图片
				NodeList bmpList = smallMonsterElement
						.getElementsByTagName("图片");
				String bmpStr = bmpList.item(0).getChildNodes().item(0)
						.getNodeValue().trim();
				MmochatRoleBmpType type = MmochatRoleBmpType.valueOf(bmpStr);
				if (type == null) {
					throw new RuntimeException("BOSS的图片非法");
				}
				smallMonster.setBmpType(type);

				// 读取等级类型
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("等级类型");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						MmochatBossLevelType levelType = MmochatBossLevelType
								.valueOf(str);
						smallMonster.setLevelType(levelType);
					}
				}
				// 读取等级
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("等级");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的等级不是数字");
						}
						smallMonster.setLevel(num);
						if (smallMonster.getLevelType() == null) {
							smallMonster
									.setLevelType(MmochatBossLevelType.自身等级);
						}
					} else {
						// 未设置等级
						smallMonster.setLevelType(MmochatBossLevelType.队伍最高等级);
					}
				}
				// 读取技能门派
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("技能门派");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						smallMonster.setFamily(MmochatFamilyType.valueOf(str));
					}
				}
				// 读取道行倍数
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("道行倍数");

					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						double num = 0;
						try {
							num = Double.parseDouble(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的道行倍数不是数字");
						}
						smallMonster.setDaoParam(num);
					}
				}

				// 设置道行
				if (smallMonster.getLevel() >= 0) {
					smallMonster
							.setDao((int) (smallMonster.getDaoParam() * MmochatBattleService
									.getStandardDao(smallMonster.getLevel(), 0)));
				}
				// 读取装备锻造等级
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("装备锻造等级");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的装备锻造等级不是数字");
						}
						smallMonster.setEquipLevel(num);
					}
				}
				// 读取队伍伤害输出人数
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("队伍伤害输出人数");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						double num = 0;
						try {
							num = Double.parseDouble(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的队伍伤害输出人数不是数字");
						}
						smallMonster.setTeamNum(num);
					}
				}
				// 读取消灭回合数
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("消灭回合数");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						double num = 0;
						try {
							num = Double.parseDouble(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的消灭回合数不是数字");
						}
						smallMonster.setKillRound(num);
					}
				}
				// 读取物伤系数
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("物伤系数");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						double num = 0;
						try {
							num = Double.parseDouble(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的物伤系数不是数字");
						}
						smallMonster.setPhysical(num);
					}
				}
				// 读取法伤系数
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("法伤系数");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						double num = 0;
						try {
							num = Double.parseDouble(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的法伤系数不是数字");
						}
						smallMonster.setMagic(num);
					}
				}
				// 读取速度系数
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("速度系数");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的速度系数不是数字");
						}
						smallMonster.setSpeedPointAddType(num);
					}
				}
				// 读取技能目标数
				NodeList targetNumList = smallMonsterElement
						.getElementsByTagName("技能目标数");
				if (targetNumList.getLength() > 0) {
					String targetNum = targetNumList.item(0).getChildNodes()
							.item(0).getNodeValue().trim();
					try {
						int num = Integer.parseInt(targetNum.trim());
						smallMonster.setBossMaxSkillTargetNum(num);
					} catch (Exception e) {
						e.printStackTrace();
						throw new RuntimeException("技能目标数不是数字");
					}
				}

				// 读取物理闪避
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("物理闪避");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的物理闪避不是数字");
						}
						smallMonster.setPhysicalAvoid(num);
					}
				}

				// 读取法术闪避
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("法术闪避");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的法术闪避不是数字");
						}
						smallMonster.setMagicAvoid(num);
					}
				}

				// 读取物理暴击
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("物理暴击");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的物理暴击不是数字");
						}
						smallMonster.setPhysicalDeadlyAttack(num);
					}
				}

				// 读取法术暴击
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("法术暴击");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的法术暴击不是数字");
						}
						smallMonster.setMagicDeadlyAttack(num);
					}
				}

				// 读取物理暴击抵抗
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("物理暴击抵抗");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的物理暴击抵抗不是数字");
						}
						smallMonster.setPhysicalDeadlyAttackDefend(num);
					}
				}

				// 读取法术暴击抵抗
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("法术暴击抵抗");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的法术暴击抵抗不是数字");
						}
						smallMonster.setMagicDeadlyAttackDefend(num);
					}
				}

				// 读取物理致命一击
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("物理致命一击");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的物理致命一击不是数字");
						}
						smallMonster.setPhysicalDoubleAttack(num);
					}
				}

				// 读取法术致命一击
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("法术致命一击");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的法术致命一击不是数字");
						}
						smallMonster.setMagicDoubleAttack(num);
					}
				}

				// 读取物理致命抵抗
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("物理致命抵抗");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的物理致命抵抗不是数字");
						}
						smallMonster.setPhysicalDoubleAttackDefend(num);
					}
				}

				// 读取法术致命抵抗
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("法术致命抵抗");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的法术致命抵抗不是数字");
						}
						smallMonster.setMagicDoubleAttackDefend(num);
					}
				}

				// 读取物理破防
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("物理破防");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的物理破防不是数字");
						}
						smallMonster.setPhysicalDefendIgnore(num);
					}
				}

				// 读取法术破防
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("法术破防");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的法术破防不是数字");
						}
						smallMonster.setMagicDefendIgnore(num);
					}
				}

				// 读取封印抵抗
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("封印抵抗");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的封印抵抗不是数字");
						}
						smallMonster.setAntiSeal(num);
					}
				}

				// 读取冰冻抵抗
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("冰冻抵抗");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的冰冻抵抗不是数字");
						}
						smallMonster.setAntiFreeze(num);
					}
				}

				// 读取混乱抵抗
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("混乱抵抗");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的混乱抵抗不是数字");
						}
						smallMonster.setAntiConfuse(num);
					}
				}

				// 读取忽视封印抵抗
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("忽视封印抵抗");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的忽视封印抵抗不是数字");
						}
						smallMonster.setIgnoreAntiSeal(num);
					}
				}

				// 读取忽视冰冻抵抗
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("忽视冰冻抵抗");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的忽视冰冻抵抗不是数字");
						}
						smallMonster.setIgnoreAntiFreeze(num);
					}
				}

				// 读取忽视混乱抵抗
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("忽视混乱抵抗");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的忽视混乱抵抗不是数字");
						}
						smallMonster.setIgnoreAntiConfuse(num);
					}
				}

				// 读取强化封印
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("强化封印");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的强化封印不是数字");
						}
						smallMonster.setStrengthenSeal(num);
					}
				}

				// 读取强化冰冻
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("强化冰冻");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的强化冰冻不是数字");
						}
						smallMonster.setStrengthenFreeze(num);
					}
				}

				// 读取强化混乱
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("强化混乱");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的强化混乱不是数字");
						}
						smallMonster.setStrengthenConfuse(num);
					}
				}

				// 读取物理免疫
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("物理免疫");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的物理免疫不是数字");
						}
						smallMonster.setPhysicalDefendPercent(num);
					}
				}

				// 读取法术免疫
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("法术免疫");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的法术免疫不是数字");
						}
						smallMonster.setMagicDefendPercent(num);
					}
				}

				// 读取抗雷
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("抗雷");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的抗雷不是数字");
						}
						smallMonster.setAntiGodSkill(num);
					}
				}

				// 读取抗水
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("抗水");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的抗水不是数字");
						}
						smallMonster.setAntiHumanSkill(num);
					}
				}

				// 读取抗毒
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("抗毒");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的抗毒不是数字");
						}
						smallMonster.setAntiDevilSkill(num);
					}
				}

				// 读取忽视抗雷
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("忽视抗雷");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的忽视抗雷不是数字");
						}
						smallMonster.setIgnoreAntiGodSkill(num);
					}
				}
				// 读取忽视抗水
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("忽视抗水");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的忽视抗水不是数字");
						}
						smallMonster.setIgnoreAntiHumanSkill(num);
					}
				}

				// 读取忽视抗毒
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("忽视抗毒");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的忽视抗毒不是数字");
						}
						smallMonster.setIgnoreAntiDevilSkill(num);
					}
				}

				// 读取神圣物理伤害
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("神圣物理伤害");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的神圣物理伤害不是数字");
						}
						smallMonster.setSuperPhysicalAttack(num);
					}
				}

				// 读取神圣法术伤害
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("神圣法术伤害");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						int num = 0;
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException("BOSS的神圣法术伤害不是数字");
						}
						smallMonster.setSuperSpritAttack(num);
					}
				}

				// 读取是否能复活
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("复活");
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						if (str.equals("能")) {
							smallMonster.setCanRescure(true);
						} else if (str.equals("不能")) {
							smallMonster.setCanRescure(false);
						} else {
							throw new RuntimeException("BOSS的复活项非法,只能填<能>或<不能>");
						}
					}
				}
				// 读取常规攻击模式
				NodeList normalModeList = smallMonsterElement
						.getElementsByTagName("常规攻击");
				if (normalModeList.getLength() > 0) {
					Node normalMode = normalModeList.item(0);
					if (normalMode.getNodeType() == Node.ELEMENT_NODE) {
						MmochatAttackModeOfNormal normalAttackMode = new MmochatAttackModeOfNormal();
						Element normalElement = (Element) normalMode;
						// 读取物攻机率
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("物攻机率");
							if (nodeList.getLength() > 0) {
								String str = nodeList.item(0).getChildNodes()
										.item(0).getNodeValue().trim();
								int num = 0;
								try {
									num = Integer.parseInt(str.trim());
								} catch (Exception e) {
									e.printStackTrace();
									throw new RuntimeException(
											"加载任务时，BOSS的物攻机率不是数字,taskId=");
								}
								normalAttackMode
										.setPhysicalAttackOpportunity(num);
							}
						}
						// 读取法攻机率
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("法攻机率");
							if (nodeList.getLength() > 0) {
								String str = nodeList.item(0).getChildNodes()
										.item(0).getNodeValue().trim();
								int num = 0;
								try {
									num = Integer.parseInt(str.trim());
								} catch (Exception e) {
									e.printStackTrace();
									throw new RuntimeException(
											"加载任务时，BOSS的法攻机率不是数字,taskId=");
								}
								normalAttackMode.setMagicAttackOppotunity(num);
							}
						}
						// 读取障碍技能机率
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("障碍机率");
							if (nodeList.getLength() > 0) {
								String str = nodeList.item(0).getChildNodes()
										.item(0).getNodeValue().trim();
								int num = 0;
								try {
									num = Integer.parseInt(str.trim());
								} catch (Exception e) {
									e.printStackTrace();
									throw new RuntimeException(
											"加载任务时，BOSS的障碍机率不是数字,taskId=");
								}
								normalAttackMode.setLimitOppotunity(num);
							}
						}
						// 读取辅助技能机率
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("辅助机率");
							if (nodeList.getLength() > 0) {
								String str = nodeList.item(0).getChildNodes()
										.item(0).getNodeValue().trim();
								int num = 0;
								try {
									num = Integer.parseInt(str.trim());
								} catch (Exception e) {
									e.printStackTrace();
									throw new RuntimeException(
											"加载任务时，BOSS的辅助机率不是数字,taskId=");
								}
								normalAttackMode.setFuZhuOppotunity(num);
							}
						}
						smallMonster.setAttackMode_normal(normalAttackMode);
					}
				} else {
					throw new RuntimeException("加载任务时，BOSS的常规攻击未设置,taskId=");
				}

				// 读取特殊技能模式
				NodeList specialSkillModeList = smallMonsterElement
						.getElementsByTagName("特殊技能");
				if (specialSkillModeList.getLength() > 0) {
					Node normalMode = specialSkillModeList.item(0);
					if (normalMode.getNodeType() == Node.ELEMENT_NODE) {
						MmochatAttackModeOfSpecialSkill specialSkillMode = new MmochatAttackModeOfSpecialSkill();
						Element normalElement = (Element) normalMode;
						// 读取血量底于多少百分比可能触发
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("血量底于多少百分比可能触发");
							if (nodeList.getLength() > 0) {
								String str = nodeList.item(0).getChildNodes()
										.item(0).getNodeValue().trim();
								int num = 0;
								try {
									num = Integer.parseInt(str.trim());
								} catch (Exception e) {
									e.printStackTrace();
									throw new RuntimeException(
											"加载任务时，BOSS的特殊技能<血量底于多少百分比可能触发>不是数字,taskId=");
								}
								specialSkillMode.setStartBloodPercent(num);
							}
						}
						// 读取触发机率
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("触发机率");
							if (nodeList.getLength() > 0) {
								String str = nodeList.item(0).getChildNodes()
										.item(0).getNodeValue().trim();
								int num = 0;
								try {
									num = Integer.parseInt(str.trim());
								} catch (Exception e) {
									e.printStackTrace();
									throw new RuntimeException(
											"加载任务时，BOSS的特殊技能触发机率不是数字,taskId=");
								}
								specialSkillMode.setOpportunity(num);
							}
						}
						// 读取技能类型
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("技能类型");
							String str = nodeList.item(0).getChildNodes().item(
									0).getNodeValue().trim();
							MmochatActionType actionType = null;
							try {
								actionType = MmochatActionType.valueOf(str);
							} catch (Exception e) {
								e.printStackTrace();
								throw new RuntimeException(
										"加载任务时，BOSS的特殊技能<技能类型>非法,taskId=");
							}
							specialSkillMode.setActionType(actionType);
						}
						// 读取执行时间
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("执行时间");
							String str = nodeList.item(0).getChildNodes().item(
									0).getNodeValue().trim();
							if (str != null && str.equals("下个回合")) {
								specialSkillMode.setNextRound(true);
							}
						}
						// 读取系统提示
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("系统提示");
							String str = nodeList.item(0).getChildNodes().item(
									0).getNodeValue().trim();
							if (str != null) {
								specialSkillMode.setHint(str);
							}
						}
						smallMonster.getAttackModeOfSpecialSkill().add(
								specialSkillMode);
					}
				}

				// 读取自己补血模式
				NodeList addBloodModeList = smallMonsterElement
						.getElementsByTagName("自己补血");
				if (addBloodModeList.getLength() > 0) {
					Node normalMode = addBloodModeList.item(0);
					if (normalMode.getNodeType() == Node.ELEMENT_NODE) {
						MmochatAttackModeOfAddBlood addBloodAttackMode = new MmochatAttackModeOfAddBlood();
						Element normalElement = (Element) normalMode;
						// 读取血量底于多少百分比可能触发
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("血量底于多少百分比可能触发");
							String str = nodeList.item(0).getChildNodes().item(
									0).getNodeValue().trim();
							int num = 0;
							try {
								num = Integer.parseInt(str.trim());
							} catch (Exception e) {
								e.printStackTrace();
								throw new RuntimeException(
										"加载任务时，BOSS的<血量底于多少百分比可能触发>不是数字,taskId=");
							}
							addBloodAttackMode.setTriggerBloodPercent(num);

						}
						// 读取补血机率
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("补血机率");

							String str = nodeList.item(0).getChildNodes().item(
									0).getNodeValue().trim();
							int num = 0;
							try {
								num = Integer.parseInt(str.trim());
							} catch (Exception e) {
								e.printStackTrace();
								throw new RuntimeException(
										"加载任务时，BOSS的补血机率不是数字,taskId=");
							}
							addBloodAttackMode.setAddBloodOpportunity(num);

						}
						// 读取补多少百分比的血
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("补多少百分比的血");
							if (nodeList.getLength() > 0) {
								String str = nodeList.item(0).getChildNodes()
										.item(0).getNodeValue().trim();
								int num = 0;
								try {
									num = Integer.parseInt(str.trim());
								} catch (Exception e) {
									e.printStackTrace();
									throw new RuntimeException(
											"加载任务时，BOSS的<补多少百分比的血>不是数字,taskId=");
								}
								addBloodAttackMode.setAddBloodPercent(num);
							}
						}
						smallMonster.setAttackMode_addBlood(addBloodAttackMode);
					}
				}

				// 读取救助队友模式
				NodeList rescueTeamerModeList = smallMonsterElement
						.getElementsByTagName("救活死亡队友");
				if (rescueTeamerModeList.getLength() > 0) {
					Node normalMode = rescueTeamerModeList.item(0);
					if (normalMode.getNodeType() == Node.ELEMENT_NODE) {
						MmochatAttackModeOfRescueTeamer rescueTeamerAttackMode = new MmochatAttackModeOfRescueTeamer();
						Element normalElement = (Element) normalMode;
						// 读取触发机率
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("触发机率");
							String str = nodeList.item(0).getChildNodes().item(
									0).getNodeValue().trim();
							int num = 0;
							try {
								num = Integer.parseInt(str.trim());
							} catch (Exception e) {
								e.printStackTrace();
								throw new RuntimeException(
										"加载任务时，BOSS的救人的<触发机率>不是数字,taskId=");
							}
							rescueTeamerAttackMode.setRescueOpportunity(num);

						}
						// 读取补多少百分比的血
						{
							NodeList nodeList = normalElement
									.getElementsByTagName("补多少百分比的血");

							String str = nodeList.item(0).getChildNodes().item(
									0).getNodeValue().trim();
							int num = 0;
							try {
								num = Integer.parseInt(str.trim());
							} catch (Exception e) {
								e.printStackTrace();
								throw new RuntimeException(
										"加载任务时，BOSS的救人的<补多少百分比的血>不是数字,taskId=");
							}
							rescueTeamerAttackMode.setBloodPercent(num);

						}
						smallMonster
								.setAttackMode_rescueTeamer(rescueTeamerAttackMode);
					}
				}

				// 读取数量
				{
					NodeList nodeList = smallMonsterElement
							.getElementsByTagName("数量");
					int num = 1;
					if (nodeList.getLength() > 0) {
						String str = nodeList.item(0).getChildNodes().item(0)
								.getNodeValue().trim();
						try {
							num = Integer.parseInt(str.trim());
						} catch (Exception e) {
							e.printStackTrace();
							throw new RuntimeException(
									"加载任务时，小怪的num不是数字,taskId=");
						}
					}
					if (num > 0) {
						for (int i = 0; i < num; i++) {
							smallBoss.add(smallMonster.getClone());
						}
					}
				}

			}
		}
		npcBattle.setSmallBoss(smallBoss);
		return npcBattle;
	}

	public static MmochatNpcBattle getBattleModelByType(
			MmochatBattleModelType type) {
		MmochatNpcBattle battle = battleModels.get(type);
		if (battle == null) {
			return null;
		}
		return battle.getClone();
	}

	// 检查掉线的玩家
	public class CheckDeadMan implements Runnable {
		@Override
		public void run() {
			try {
				for (MmochatPlayer p : players.values()) {
					if (!p.isAlive() && !p.isDeadConnection()) {
						// 已经掉线,要考虑由于网络卡,心跳无法发出,而其实未真正掉线的情况
						// 如果在战斗中等情况,掉线后暂时不从玩家列表中删除
						try {
							if (p.isInBattle()) {
								p.setDeadConnection(true);
								MmochatBattle battle = MmochatBattleService.battles
										.get(p.getBattleId());
								if (battle != null) {
									battle.addDefaultAction(p);
									MmochatBattleService
											.checkBattleIsReady(battle);
									log.debug(p.getName()
											+ " lose connection from battle!");
									continue;
								} else {
									p.leaveBattle();
								}
							}
							// 正在观战中
							if (p.isInWatchingBattle()) {
								MmochatBattle battle = MmochatBattleService.battles
										.get(p.getWatchBattleId());
								if (battle != null) {
									p.setDeadConnection(true);
									log
											.debug(p.getName()
													+ " lose connection from watch battle!");
									continue;
								} else {
									p.leaveWatchingBattle();
								}
							}
						} catch (Exception e) {
							e.printStackTrace();
						}

						// 如果允许删除玩家(将其加入离线玩家列表，不执行数据库操作)
						leaveGame(p);
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	// 检查玩家真正离线
	public class CheckManLeaveGame implements Runnable {
		public void run() {
			try {
				for (MmochatPlayer me : offlinePlayers.values()) {
					if (me.isLeaveGame()) {
						if (me.isGuest()) {
							// 游客
							for (Entry<String, Integer> entry : guestMap
									.entrySet()) {
								Integer roleId = entry.getValue();
								if (roleId != null && roleId == me.getRoleId()) {
									String str = entry.getKey();
									offlinePlayers.remove(roleId);
									if (str != null) {
										guestMap.remove(str);
										log.debug("游客" + str + "从内存中移除");
									}
									break;
								}
							}
						} else {
							// 放入队列中
							needToSaveLeaveGameSqlPlayerMap.put(me.getRoleId(),
									me);

							// 如果在观看录像，则删除
							try {
								MmochatBattleRecordPlayer record = MmochatBattleService.battleRecordPlayers
										.get(me.getRoleId());
								if (record != null) {
									record.quit();
									MmochatBattleService.battleRecordPlayers
											.remove(record.getRoleId());
								}
							} catch (Exception e) {
								e.printStackTrace();
							}
						}
					}
				}

				// 最高在线人数监测
				int curOnlineNum = players.size();
				MmochatStatisticsService.todayMaxOnlineNum = Math.max(
						MmochatStatisticsService.todayMaxOnlineNum,
						curOnlineNum);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	public static boolean isPlayerOnline(int roleId) {
		if (players.get(roleId) != null) {
			return true;
		}
		return false;
	}

	public static MmochatPlayer getRoleFromBufferBySkyId(long skyId) {
		Integer roleId = players_skyIdMap.get(skyId);
		if (roleId != null) {
			return players.get(roleId);
		}

		roleId = offlinePlayers_skyIdMap.get(skyId);
		if (roleId != null) {
			return offlinePlayers.get(roleId);
		}

		if (MmochatMain.serverType != MmochatServerType.跨服战服务器) {
			for (MmochatPlayer me : MmochatGmService.gmOptionPlayers.values()) {
				if (me.getSkyId() == skyId) {
					return me;
				}
			}
		}
		return null;
	}

	public static MmochatPlayer getRoleFromBuffer(int roleId) {
		MmochatPlayer me = players.get(roleId);
		if (me == null) {
			me = offlinePlayers.get(roleId);
		}
		if (me == null) {
			me = MmochatGmService.gmOptionPlayers.get(roleId);
			if (me != null) {
				log.debug("从客服调用玩家缓存中读取角色:" + me.getName());
				me.setLatestActiveTime(System.currentTimeMillis());
			}
		}
		if (me == null) {
			me = needToSaveLeaveGameSqlPlayerMap.get(roleId);
		}
		if (me != null && MmochatMain.serverType == MmochatServerType.跨服战服务器) {
			me.setLastActionTime();
			me.setDeadConnection(false);
		}
		return me;
	}

	// 给内存中的玩家设置新的对象
	// public static void setPlayerNewValue1(MmochatPlayer newMe) {
	// if (newMe == null) {
	// return;
	// }
	// if (players.containsKey(newMe.getRoleId())) {
	// players.put(newMe.getRoleId(), newMe);
	// if (!newMe.isGuest()) {
	// players_skyIdMap.put(newMe.getSkyId(), newMe.getRoleId());
	// }
	// }
	//
	// if (offlinePlayers.containsKey(newMe.getRoleId())) {
	// offlinePlayers.put(newMe.getRoleId(), newMe);
	// if (!newMe.isGuest()) {
	// offlinePlayers_skyIdMap
	// .put(newMe.getSkyId(), newMe.getRoleId());
	// }
	// // offlinePlayers_skyIdMap.put(newMe.getSkyId(), newMe.getRoleId());
	// }
	//
	// if (MmochatGmService.gmOptionPlayers.containsKey(newMe
	// .getRoleId())) {
	// MmochatGmService.gmOptionPlayers.put(newMe.getRoleId(), newMe);
	// }
	// MmochatMap curMap = MmochatMapService.maps.get(newMe.getMapId());
	// if (curMap != null) {
	// if (curMap.getLineRoleMap(newMe.getLine()).containsKey(
	// newMe.getRoleId())) {
	// curMap.addRole(newMe.getLine(), newMe);
	// }
	// }
	// }

	// 玩家离开游戏
	public static void leaveGame(MmochatPlayer me) {
		leaveGame(me, true);
	}

	// 玩家离开游戏(可能在游戏中掉线)
	public static void leaveGame(MmochatPlayer me, boolean addToOfflinePlayer) {
		if (me == null) {
			return;
		}
		me.setDeadConnection(true);
		if (me.isInBattle() || me.isInWatchingBattle()) {
			// 正在战斗中,不清除玩家
			return;
		}
		log.debug(me.getName() + " leave the game!");

		// 角色下线相关处理

		// 取消交易
		me.stopDeal();

		// 离队
		if (me.isInTeam()) {
			MmochatTeam team = MmochatTeamService.teams.get(me.getTeamId());
			if (team != null) {
				team.leaveTeam(me.getRoleId());
			} else {
				me.leaveTeam();
			}
		}

		MmochatMap curMap = MmochatMapService.maps.get(me.getMapId());
		if (curMap != null) {
			curMap.delRole(me.getLine(), me);
		}

		// 将其放入离线玩家列表
		if (addToOfflinePlayer) {
			me.setLatest_offline_time((new Date()).getTime());
			offlinePlayers.put(me.getRoleId(), me);
			if (!me.isGuest()) {
				offlinePlayers_skyIdMap.put(me.getSkyId(), me.getRoleId());
			}

			nameMap.remove(me.getName());
			players.remove(me.getRoleId());
			players_skyIdMap.remove(me.getSkyId());
		} else {
			// 由于保存离线数据可能要10分钟之久，故应该先临时放入 offlinePlayers中
			me.setLatest_offline_time((new Date()).getTime());
			offlinePlayers.put(me.getRoleId(), me);
			if (!me.isGuest()) {
				offlinePlayers_skyIdMap.put(me.getSkyId(), me.getRoleId());
			}

			nameMap.remove(me.getName());
			players.remove(me.getRoleId());
			players_skyIdMap.remove(me.getSkyId());

			// 放入队列中
			needToSaveLeaveGameSqlPlayerMap.put(me.getRoleId(), me);
		}

		try {
			// 伤害、速度在线排行
			MmochatNpcService.dealOnlineRank(me);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// 玩家回到游戏
	public static void enterGame(MmochatPlayer me, UserConnInfo connInfo,
			Mmochat_1_1S pack) {
		if (me == null || connInfo == null) {
			return;
		}
		log.debug(me.getName() + " enter the game!");
		// 更新内存数据
		me.setUserConnInfo(connInfo);
		me.setLatestActiveTime(System.currentTimeMillis());
		MmochatMap curMap = MmochatMapService.getMapByMapId(me.getMapId());
		if (curMap == null) {
			// 地图不存在,可能之前所在临时地图已经关闭,将其转移到固定地图
			MmochatMapTransPoint newPos = MmochatMap
					.getMapWhenTempMapNotFound(me.getMapId());
			curMap = MmochatMapService.getMapByMapId(newPos.getTransToMapId());
			me.setX(newPos.getNewMapX());
			me.setY(newPos.getNewMapY());
			me.setMapId(newPos.getTransToMapId());
		}
		int line = me.getLine();
		curMap.addRole(line, me);
		nameMap.put(me.getName(), me.getRoleId());
		players.put(me.getRoleId(), me);
		if (!me.isGuest()) {
			players_skyIdMap.put(me.getSkyId(), me.getRoleId());
		}

		// 下发组队状态
		MmochatTeamService.notifyTeamStateToClient(me);

		// 将其它玩家加入我的视界
		me.getSceenRoles().clear();
		for (MmochatPlayer other : curMap.getLineRoleMap(line).values()) {
			try {
				// 换线时最多不能超过15个玩家，以免卡
				if (me.getSceenRoles().size() >= Math.min(15, me
						.getMax_screen_role_num())) {
					break;
				}
				if (other.getRoleId() != me.getRoleId()) {
					if (Math.abs(other.getX() - me.getX()) < MmochatConstant.screenWidth
							&& Math.abs(other.getY() - me.getY()) < MmochatConstant.screenHeight) {
						// 视界范围内
						if (me.getMyEnermys().get(other.getRoleId()) != null) {
							// 在我的黑名单中
							continue;
						} else if (me.getShowRoleSet() == MmochatShowRoleSet.隐藏所有人) {
							continue;
						} else if (me.getShowRoleSet() == MmochatShowRoleSet.只显示队长) {
							if (MmochatTeamService.getTeamState(other) == MmochatTeamStateType.队长) {
								if (pack != null) {
									pack.addSceenRole(other);
								}
								me.addSceenRole(other.getRoleId(), other
										.getStateValue(me));
							}
						} else if (me.getShowRoleSet() == MmochatShowRoleSet.只显示好友) {
							if (me.getMyDearFriends().get(other.getRoleId()) != null) {
								if (pack != null) {
									pack.addSceenRole(other);
								}
								me.addSceenRole(other.getRoleId(), other
										.getStateValue(me));
							}
						} else if (me.getShowRoleSet() == MmochatShowRoleSet.显示所有人) {
							if (pack != null) {
								pack.addSceenRole(other);
							}
							me.addSceenRole(other.getRoleId(), other
									.getStateValue(me));
						}
					}
				}
			} catch (Exception e) {
			}
		}

	}

	public static SkymobiHandler getCommonHandler() {
		return commonHandler;
	}

	@Override
	public void initSkymobiHandlerComplete(SkymobiHandler skymobiHandler) {
		commonHandler = skymobiHandler;
	}

	// 读取角色,支持断线重连,并能更新活动时间
	public static MmochatPlayer getPlayerByRoleId(SkymobiProtocolMessage req,
			int roleId) {
		return getPlayerByRoleId(req.getSkyId(), req.getUserConnInfo(), roleId);
	}

	public static MmochatPlayer getPlayerByRoleId(long skyId,
			UserConnInfo conn, int roleId) {
		return getPlayerByRoleId(skyId, true, conn, roleId);
	}

	public static MmochatPlayer getPlayerByRoleId(UserConnInfo conn, int roleId) {
		return getPlayerByRoleId(0, false, conn, roleId);
	}

	public static MmochatPlayer getPlayerByRoleId(long skyId,
			boolean checkSkyId, UserConnInfo conn, int roleId) {
		if (roleId >= MmochatConstant.guestRoleIdStart && roleId < 10000000) {
			checkSkyId = false;
		}
		MmochatPlayer me = players.get(roleId);
		if (me == null) {
			me = offlinePlayers.get(roleId);
			if (me != null) {
				me.setLastActionTime();
				me.setDeadConnection(false);
				nameMap.put(me.getName(), me.getRoleId());
				players.put(me.getRoleId(), me);
				if (!me.isGuest()) {
					players_skyIdMap.put(me.getSkyId(), me.getRoleId());
				}

				offlinePlayers.remove(roleId);
				if (roleId < MmochatConstant.guestRoleIdStart) {
					offlinePlayers_skyIdMap.remove(me.getSkyId());
				}
			} else if (MmochatMain.serverType != MmochatServerType.跨服战服务器) {
				me = MmochatGmService.gmOptionPlayers.get(roleId);
				if (me != null) {
					me.setLastActionTime();
					me.setDeadConnection(false);
					nameMap.put(me.getName(), me.getRoleId());
					players.put(me.getRoleId(), me);
					if (!me.isGuest()) {
						players_skyIdMap.put(me.getSkyId(), me.getRoleId());
					}

					MmochatGmService.gmOptionPlayers.remove(roleId);
				}
			}
			if (me == null) {
				me = needToSaveLeaveGameSqlPlayerMap.get(roleId);
				if (me != null) {
					me.setLastActionTime();
					me.setDeadConnection(false);
					nameMap.put(me.getName(), me.getRoleId());
					players.put(me.getRoleId(), me);
					if (!me.isGuest()) {
						players_skyIdMap.put(me.getSkyId(), me.getRoleId());
					}
				}
			}
			if (me == null) {
				// 掉线重连处理
				try {
					me = MmochatDao.getRole(roleId);
				} catch (EmptyResultDataAccessException e) {
					return null;
				} catch (Exception e) {
					e.printStackTrace();
					return null;
				}
				if (me == null) {
					return null;
				}
				me.setLastActionTime();
				me.setDeadConnection(false);
				nameMap.put(me.getName(), me.getRoleId());
				players.put(me.getRoleId(), me);
				if (!me.isGuest()) {
					players_skyIdMap.put(me.getSkyId(), me.getRoleId());
				}

				// 检查roleId-->skyId是否匹配
				if (checkSkyId && skyId != me.getSkyId()) {
					// TODO：可能是终端上传了错误的roleId上来，不作处理
					if (MmochatConstant.testErrorRoleId) {
						try {
							throw new Exception();
						} catch (Exception e) {
							e.printStackTrace();
						}
						log.error("终端上传了错误的roleId, 终端skyId=" + skyId
								+ ",错误的roleId=" + me.getRoleId());

					}
					// 查找内存中是否有此skyId的角色，作为此角色
					me = getRoleFromBufferBySkyId(skyId);
					if (me == null) {
						return null;
					}
					if (MmochatConstant.testErrorRoleId) {
						log.error("通过skyId找到正确的角色,roleId=" + me.getRoleId());
					}
				}

				// 通知好友我上线了
				for (Integer roleId1 : me.getMyFans().values()) {
					MmochatPlayer friend = players.get(roleId1);
					if (friend == null) {
						continue;
					}
					MmochatFriend friendShip = friend.getMyDearFriends().get(
							me.getRoleId());
					if (friendShip == null) {
						// 在我离线期间，这位好友将我删出好友了
						me.delFans(roleId1);
					} else {
						// 上线消息
						friendShip.setBmpId(me.getBmpId());
						friendShip.setName(me.getName());
						friendShip.setMoodInfo(me.getMoodInfo());

						friend.addOnlineFriend(me.getRoleId());

						if (friend.getMyIdols().containsKey(me.getRoleId())) {
							MmochatChatService.sendSystemMsgToPerson(friend,
									"您的好友"
											+ MmochatUtil.wrapColor(me
													.getName(), Color.green)
											+ "上线了!");
						}
					}
				}
			} else {
				// 检查roleId-->skyId是否匹配
				if (checkSkyId && skyId != me.getSkyId()) {
					// TODO：可能是终端上传了错误的roleId上来，不作处理
					if (MmochatConstant.testErrorRoleId) {
						log.error("终端上传了错误的roleId, 终端skyId=" + skyId
								+ ",错误的roleId=" + me.getRoleId());
						try {
							throw new Exception();
						} catch (Exception e) {
							e.printStackTrace();
						}
					}
					// 查找内存中是否有此skyId的角色，作为此角色
					me = getRoleFromBufferBySkyId(skyId);
					if (me == null) {
						return null;
					}
					if (MmochatConstant.testErrorRoleId) {
						log.error("通过skyId找到正确的角色,roleId=" + me.getRoleId());
					}
				}
			}
			// 如果正在封号中，则不受理
			if (System.currentTimeMillis() < me.getLock_time_point()) {
				return null;
			}

			me.setLastActionTime();
			me.setUserConnInfo(conn);
			me.setDeadConnection(false);

			// 地图不存在,可能之前所在临时地图已经关闭,将其转移到固定地图
			MmochatMap map = MmochatMapService.getMapByMapId(me.getMapId());
			if (map == null) {
				// 地图不存在,可能之前所在临时地图已经关闭,将其转移到固定地图
				MmochatMapTransPoint newPos = MmochatMap
						.getMapWhenTempMapNotFound(me.getMapId());
				map = MmochatMapService.getMapByMapId(newPos.getTransToMapId());

				// 下发切换地图
				if (me.isInBattle()) {
					log.debug("玩家" + me.getName() + "(skyid=" + me.getSkyId()
							+ ")已进入战斗,无法传送");
					return me;
				}

				List<MmochatPlayer> members = new ArrayList<MmochatPlayer>();
				if (me.isInTeam()) {
					MmochatTeam team = MmochatTeamService.teams.get(me
							.getTeamId());
					if (team == null) {
						me.leaveTeam();
						members.add(me);
					} else {
						if (!team.isTeamLeader(me.getRoleId())) {
							log.debug("玩家" + me.getName() + "(skyid="
									+ me.getSkyId() + ")在队伍中，且不为队长，无法传送;");
							return null;
						}
						for (Integer roleId1 : team.getMemberId().values()) {
							MmochatPlayer member = MmochatMainService.players
									.get(roleId1);
							if (member != null) {
								members.add(member);
							}
						}
					}
				} else {
					members.add(me);
				}
				if (members.size() <= 0) {
					log.debug("玩家" + me.getName() + "(skyid=" + me.getSkyId()
							+ ")传送人数为0，无法传送;");
					return me;
				}

				// 将本队人马传到新地图新坐标
				MmochatMapService.tranToNewMap(null, 0, map, me.getLine(),
						newPos.getNewMapX(), newPos.getNewMapY(), members);

				log.debug("玩家" + me.getName() + "(skyid=" + me.getSkyId()
						+ ")完成传送");
				return null;
			} else {
				enterGame(me, conn, null);
			}
			return me;
		} else {
			// 如果正在封号中，则不受理
			if (System.currentTimeMillis() < me.getLock_time_point()) {
				return null;
			}

			// 检查roleId-->skyId是否匹配
			if (checkSkyId && skyId != me.getSkyId()) {
				// TODO：可能是终端上传了错误的roleId上来，不作处理
				if (MmochatConstant.testErrorRoleId) {
					log.error("终端上传了错误的roleId, 终端skyId=" + skyId
							+ ",错误的roleId=" + me.getRoleId());
					try {
						throw new Exception();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
				// 查找内存中是否有此skyId的角色，作为此角色
				me = getRoleFromBufferBySkyId(skyId);
				if (me == null) {
					return null;
				}
				if (MmochatConstant.testErrorRoleId) {
					log.error("通过skyId找到正确的角色,roleId=" + me.getRoleId());
				}
			}
			me.setUserConnInfo(conn);
			me.setLatestActiveTime(System.currentTimeMillis());
			me.setDeadConnection(false);
			me.setLastActionTime();
			return me;
		}
	}

	// 检测到加速，返回封号时间，单位：分钟
	// 加速N倍，则封号N*10分钟
	public int checkHeartBeat(MmochatPlayer me) {
		me.addHeartBeatTimes();
		long costTime = System.currentTimeMillis() - me.getHeartBeatStartTick();
		if (costTime >= MmochatConstant.heartBeatCheckIntervalOfMinute
				* MmochatConstant.MS_PER_MINUTE) {
			// 一个检测周期到了
			double aveHeartPerMin = 1.0 * me.getHeartBeatTimes()
					/ MmochatConstant.heartBeatCheckIntervalOfMinute;

			// 新的一个检测周期开始
			me.setHeartBeatTimes(0);
			me.setHeartBeatStartTick(System.currentTimeMillis());

			if (aveHeartPerMin >= MmochatConstant.maxHeartBeatTimesPerMin) {
				// 检测出加速情况
				// 放入监控名单
				speedUpRoles.put(me.getRoleId(), (int) aveHeartPerMin);
				return (int) ((aveHeartPerMin / 6 - 1) * MmochatConstant.heartBeatCheckIntervalOfMinute);
			}
		}
		return 0;
	}

	private boolean dealHeartBeatError(MmochatPlayer me) {
		if (me.getLock_time_point() < System.currentTimeMillis()) {
			int times = checkHeartBeat(me);
			if (times > 0) {
				if (MmochatConstant.isDealHeartBeatError) {
					// 使用了加速软件，封号1小时
					// 踢下线
					me.stopDeal();
					MmochatUtil.sendCommonPack(me,
							new Mmochat_ClientVersionError());

					times = Math.min(120, times);

					// 禁止登陆times分钟
					long endTime = System.currentTimeMillis() + times
							* MmochatConstant.MS_PER_MINUTE;
					try {
						MmochatDao.forbiddenRole(endTime, me.getRoleId());
					} catch (Exception e) {
						e.printStackTrace();
					}
					MmochatGmService.forbiddenReasons.put(me.getRoleId(),
							"系统检测到您使用了加速软件，根据您加速程度，对您封号" + times + "分钟!");

					me.setLock_time_point(endTime);
					return true;
				}
			}
		}
		return false;
	}

	// 1.5 心跳包
	@SkymobiService
	public SkymobiProtocolMessage handleC_1_5(SkymobiHandler handler,
			Mmochat_1_5C req) {
		// 对终端版本号不作判断
		if (/*
			 * req.getClientVersion() != MmochatMain.getClientVersion() ||
			 */req.getServerVersion() != MmochatMain.getServerVersion()) {
			// 服务端版本不一致,下发退出游戏协议
			return new Mmochat_ClientVersionError();
		} else {
			MmochatPlayer me = players.get(MmochatPlayer.getRealRoleId(req
					.getRoleId()));
			if (me == null) {
				// 掉线重连处理
				me = offlinePlayers.get(req.getRoleId());
				if (me != null) {
					me.setLastActionTime();
					me.setDeadConnection(false);
					nameMap.put(me.getName(), me.getRoleId());
					players.put(me.getRoleId(), me);
					if (!me.isGuest()) {
						players_skyIdMap.put(me.getSkyId(), me.getRoleId());
					}

					offlinePlayers.remove(req.getRoleId());
					if (!me.isGuest()) {
						offlinePlayers_skyIdMap.remove(me.getSkyId());
					}
				} else {
					me = MmochatGmService.gmOptionPlayers.get(req.getRoleId());
					if (me != null) {
						me.setLastActionTime();
						me.setDeadConnection(false);
						nameMap.put(me.getName(), me.getRoleId());
						players.put(me.getRoleId(), me);
						if (!me.isGuest()) {
							players_skyIdMap.put(me.getSkyId(), me.getRoleId());
						}

						MmochatGmService.gmOptionPlayers
								.remove(req.getRoleId());
					}
				}
				if (me == null) {
					me = needToSaveLeaveGameSqlPlayerMap.get(req.getRoleId());
					if (me != null) {
						me.setLastActionTime();
						me.setDeadConnection(false);
						nameMap.put(me.getName(), me.getRoleId());
						players.put(me.getRoleId(), me);
						if (!me.isGuest()) {
							players_skyIdMap.put(me.getSkyId(), me.getRoleId());
						}
					}
				}

				if (me == null) {
					try {
						me = MmochatDao.getRole(req.getRoleId());
					} catch (EmptyResultDataAccessException e) {
						return null;
					} catch (Exception e) {
						e.printStackTrace();
						return null;
					}
					if (me == null) {
						return null;
					}
					me.setLastActionTime();
					me.setDeadConnection(false);
					nameMap.put(me.getName(), me.getRoleId());
					players.put(me.getRoleId(), me);
					if (!me.isGuest()) {
						players_skyIdMap.put(me.getSkyId(), me.getRoleId());
					}
				}
				// 检查roleId-->skyId是否匹配
				if (req.getSkyId() != me.getSkyId()) {
					// TODO：可能是终端上传了错误的roleId上来
					if (MmochatConstant.testErrorRoleId) {
						log.error("终端上传了错误的roleId, 终端skyId=" + req.getSkyId()
								+ ",错误的roleId=" + me.getRoleId());
						try {
							throw new Exception();
						} catch (Exception e) {
							e.printStackTrace();
						}
					}
					// 查找内存中是否有此skyId的角色，作为此角色
					me = getRoleFromBufferBySkyId(req.getSkyId());
					if (me == null) {
						return null;
					}
					if (MmochatConstant.testErrorRoleId) {
						log.error("通过skyId找到正确的角色,roleId=" + me.getRoleId());
					}
				}
				me.setLastActionTime();
				me.setUserConnInfo(req.getUserConnInfo());
				me.setLatestActiveTime(System.currentTimeMillis());
				me.setDeadConnection(false);
				me.setClientVersion(req.getClientVersion());

				// 检测心跳包是否过快，防止加速软件
				if (dealHeartBeatError(me)) {
					return null;
				}

				MmochatMap map = MmochatMapService.getMapByMapId(me.getMapId());
				if (map == null) {
					// 地图不存在,可能之前所在临时地图已经关闭,将其转移到固定地图
					MmochatMapTransPoint newPos = MmochatMap
							.getMapWhenTempMapNotFound(me.getMapId());
					map = MmochatMapService.getMapByMapId(newPos
							.getTransToMapId());
					// 下发切换地图
					if (me.isInBattle()) {
						log.debug("玩家" + me.getName() + "(skyid="
								+ me.getSkyId() + ")已进入战斗,无法传送");
						return null;
					}

					List<MmochatPlayer> members = new ArrayList<MmochatPlayer>();
					if (me.isInTeam()) {
						MmochatTeam team = MmochatTeamService.teams.get(me
								.getTeamId());
						if (team == null) {
							me.leaveTeam();
							members.add(me);
						} else {
							if (!team.isTeamLeader(me.getRoleId())) {
								log.debug("玩家" + me.getName() + "(skyid="
										+ me.getSkyId() + ")在队伍中，且不为队长，无法传送;");
								return null;
							}
							for (Integer roleId1 : team.getMemberId().values()) {
								MmochatPlayer member = MmochatMainService.players
										.get(roleId1);
								if (member != null) {
									members.add(member);
								}
							}
						}
					} else {
						members.add(me);
					}
					if (members.size() <= 0) {
						log.debug("玩家" + me.getName() + "(skyid="
								+ me.getSkyId() + ")传送人数为0，无法传送;");
						return null;
					}

					// 将本队人马传到新地图新坐标
					MmochatMapService.tranToNewMap(null, 0, map, me.getLine(),
							newPos.getNewMapX(), newPos.getNewMapY(), members);

					log.debug("玩家" + me.getName() + "(skyid=" + me.getSkyId()
							+ ")完成传送");
					return null;
				} else {
					enterGame(me, req.getUserConnInfo(), null);
				}
			} else {
				// 检查roleId-->skyId是否匹配
				if (req.getSkyId() != me.getSkyId()) {
					// TODO：可能是终端上传了错误的roleId上来，不作处理
					if (MmochatConstant.testErrorRoleId) {
						log.error("终端上传了错误的roleId, 终端skyId=" + req.getSkyId()
								+ ",错误的roleId=" + me.getRoleId());
						try {
							throw new Exception();
						} catch (Exception e) {
							e.printStackTrace();
						}
					}
					// 查找内存中是否有此skyId的角色，作为此角色
					me = getRoleFromBufferBySkyId(req.getSkyId());
					if (me == null) {
						return null;
					}
					if (MmochatConstant.testErrorRoleId) {
						log.error("通过skyId找到正确的角色,roleId=" + me.getRoleId());
					}
				}
				me.setUserConnInfo(req.getUserConnInfo());
				me.setLatestActiveTime(System.currentTimeMillis());
				me.setDeadConnection(false);
				me.setClientVersion(req.getClientVersion());

				// 检测心跳包是否过快，防止加速软件
				if (dealHeartBeatError(me)) {
					return null;
				}
			}
			log.debug("收到" + me.getName() + "的心跳包!");
			return null;
		}
	}

	// 获取快捷操作
	public static CtrlTLVStructureRequest getQuickStart(int hallState,
			int roleId) {
		CreateKeyEventTlvWin tlv = new CreateKeyEventTlvWin();
		tlv.setWinType(WinType.List);
		tlv.setLeftName("确定");
		tlv.setRightName("返回");
		tlv.setTitle("快捷功能");
		tlv.setWinHeight(250);
		tlv.setWinId(MmochatConstant.TLV_WIN_QUICKSTART);
		tlv.addRightTLV(new CloseWinTLV(MmochatConstant.TLV_WIN_QUICKSTART));

		for (MmochatQickStartType type : MmochatQickStartType.values()) {
			if (type.getValue() == MmochatQickStartType.退出游戏.getValue()) {
				String item = "";
				item += type.toString();
				tlv.addItemEvent(item, new CallLocalFuncTlv(
						MmochatConstant.funcode_quitGameFunc));
				continue;
			}
			String item = "";
			item += type.toString();
			tlv.addItemEvent(item, new ClearDataTLV(), new AddDataTLV(
					(int) roleId), new AddDataTLV((int) type.getValue()),
					new SendDataTLV(MmochatConstant.getClientModuleId(),
							MmochatMain.getModuleInstID(),
							MmochatConstant.MSGCODE_MMOCHAT_C_6_3,
							(int) MmochatConstant.quickStartVersion),
					new ShowWaitingMsgBoxTLV());
		}

		CtrlTLVStructureRequest pack = new CtrlTLVStructureRequest(hallState,
				new CloseWinTLV(MmochatConstant.TLV_WIN_QUICKSTART), tlv);
		pack.setSrcId(MmochatMain.getModuleInstID());
		pack.setDstId(MmochatConstant.getClientModuleId());
		pack.setMsgCode(MmochatConstant.MSGCODE_MMOCHAT_S_1_6);
		return pack;
	}

	// 获取8键功能
	public static CtrlTLVStructureRequest getKey8Func(int hallState, int roleId) {
		CreateKeyEventTlvWin tlv = new CreateKeyEventTlvWin();
		tlv.setWinType(WinType.List);
		tlv.setLeftName("确定");
		tlv.setRightName("返回");
		tlv.setTitle("团队");
		tlv.setWinHeight(208);
		tlv.setWinId(MmochatConstant.TLV_WIN_MULTIPLAYERTEAM);
		tlv
				.addRightTLV(new CloseWinTLV(
						MmochatConstant.TLV_WIN_MULTIPLAYERTEAM));

		for (MmochatMultiPlayerTeamType type : MmochatMultiPlayerTeamType
				.values()) {
			String item = "";
			item += type.toString();
			tlv.addItemEvent(item, new ClearDataTLV(), new AddDataTLV(
					(int) roleId), new AddDataTLV((int) type.getValue()),
					new SendDataTLV(MmochatConstant.getClientModuleId(),
							MmochatMain.getModuleInstID(),
							MmochatConstant.MSGCODE_MMOCHAT_C_6_12,
							(int) MmochatConstant.multiPlayerTeamVersion),
					new ShowWaitingMsgBoxTLV());
		}

		CtrlTLVStructureRequest pack = new CtrlTLVStructureRequest(hallState,
				new CloseWinTLV(MmochatConstant.TLV_WIN_MULTIPLAYERTEAM), tlv);
		pack.setSrcId(MmochatMain.getModuleInstID());
		pack.setDstId(MmochatConstant.getClientModuleId());
		pack.setMsgCode(MmochatConstant.MSGCODE_MMOCHAT_S_1_17);
		return pack;
	}

	// 1.1进入游戏
	@SuppressWarnings("deprecation")
	@SkymobiService
	public SkymobiProtocolMessage handleC_1_1(SkymobiHandler handler,
			Mmochat_1_1C req) {
		if (MmochatGmService.isSystemExit()) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器正在重启，请稍候再进!");
		}

		// 如果在观看录像，则删除
		try {
			MmochatBattleRecordPlayer record = MmochatBattleService.battleRecordPlayers
					.get(req.getRoleId());
			if (record != null) {
				MmochatBattleService.battleRecordPlayers.remove(record
						.getRoleId());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		// 进入跨服战服务器
		if (MmochatMain.serverType == MmochatServerType.跨服战服务器) {
			Date now = new Date();
			SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
			String curTimeString = sdf.format(now);

			// 如果在内存中，则允许登陆
			boolean isInBuffer = false; // 是否在内存中
			MmochatPlayer me = getRoleFromBufferBySkyId(req.getSkyId());
			if (me == null) {
				MmochatTempUserInfo userInfo = MmochatMultiServerPkService.tmpUsers
						.get(req.getSkyId());
				if (userInfo == null) {
					return MmochatUtil.msgbox(req.getHallState(),
							"跨服专区需要在您所有的区服内，向特定NPC申请后，再由此登陆!" + "当前跨服区时间:"
									+ curTimeString);
				}
				synchronized (multiServerLoginLock) {
					try {
						Thread.sleep(50);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}

				try {
					me = MmochatMain.serverListDaoService.getRole(userInfo
							.getRoleId(), userInfo.getSrcInstId());
				} catch (EmptyResultDataAccessException e) {
					return MmochatUtil.msgbox(req.getHallState(),
							"当前角色不存在，如有疑问，请咨询客服电话0571-85222407");
				} catch (Exception e) {
					e.printStackTrace();
					return MmochatUtil.msgbox(req.getHallState(),
							"当前服务器忙,请稍候再试!");
				}

				if (me == null) {
					return MmochatUtil.msgbox(req.getHallState(),
							"跨服专区需要在您所有的区服内，向特定NPC申请后，再由此登陆!" + "当前跨服区时间:"
									+ curTimeString + "!");
				}
				me.setRoleId(me.getRoleId() + 10000000
						* userInfo.getSrcServerId());
				me.setRegServerInstId(userInfo.getSrcInstId());
			} else {
				isInBuffer = true;
			}
			me.setUserConnInfo(req.getUserConnInfo());

			// 登陆跨服游戏服
			// 各项赛事时间上必需独立、不重叠；这里需要通过时间来判断玩家参加的是哪个比赛
			if ((now.getDay() == 4)
					&& ((now.getHours() == 19 && now.getMinutes() >= 30)
							|| now.getHours() == 20 || now.getHours() == 21)) {
				/************************* 跨服武道 ************************/
				// 周四19:30-22:00为跨服武道时间
				if (!isInBuffer) {
					// 如果不在内存中，则只能在19:30-20:00进场
					if ((now.getDay() != 4) || now.getHours() != 19
							|| now.getMinutes() < 30) {
						return MmochatUtil.msgbox(req.getHallState(),
								"跨服武道入场时间:每周四的19:30-20:00,现在不是入场时间!当前跨服服务器时间为"
										+ curTimeString
										+ "!如果您是从跨服专区掉线，10分钟内仍可进入跨服专区!");
					}
				}
				// 设置地图、线路、坐标
				int mapId, line, posX, posY;
				int teamIndex = me.getLevel() / 10 - 3;
				mapId = MmochatConstant.mapId_30级跨服武道会 + teamIndex;
				int[] level_line_map = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
				if (teamIndex >= level_line_map.length) {
					line = level_line_map[level_line_map.length - 1];
				} else {
					line = level_line_map[teamIndex];
				}
				int index = me.getRegServerInstId() % 9;
				int row = index / 3;
				int col = index % 3;
				posX = MmochatUtil.getRandomValue(50 + (col * 200),
						130 + (col * 200));
				posY = MmochatUtil.getRandomValue(50 + (row * 200),
						130 + (row * 200));

				int hour = now.getHours();
				int min = now.getMinutes();
				String time = hour + ":";
				if (min < 10) {
					time += "0" + min;
				} else {
					time += min;
				}
				String hint = "现在是" + time + "!";
				hint += MmochatUtil.wrapColor("跨服武道中允许逃跑(即使死亡或被障碍)，逃跑即认输!",
						Color.red)
						+ "组队时逃跑只能由队长执行!";

				MmochatMultiServerPkService.enterMultiServer(me, isInBuffer,
						req.getHallState(), mapId, line, posX, posY, hint);
			} else if (now.getHours() <= 18 || now.getHours() >= 23) {
				/************************* 跨服擂台 ************************/
				// 每日23:00-19:00为跨服擂台
				// 设置地图、线路、坐标
				int mapId, line, posX, posY;
				mapId = MmochatConstant.mapId_跨服擂台;
				line = Math.max(0, me.getLevel() - 30) / 10;
				posX = 195;
				posY = 98;

				int hour = now.getHours();
				int min = now.getMinutes();
				String time = hour + ":";
				if (min < 10) {
					time += "0" + min;
				} else {
					time += min;
				}
				String hint = "欢迎进入跨服擂台,现在是" + time + "!"
						+ "默认30级别进入1线,...,120级别进入10线," + "您可以换线进入其它级别线路!";

				MmochatMultiServerPkService.enterMultiServer(me, isInBuffer,
						req.getHallState(), mapId, line, posX, posY, hint);
			}
			return null;
		}

		MmochatPlayer role = players.get(req.getRoleId());
		MmochatMap curMap;

		// 将玩家从赌场中移除
		MmochatBetService.removePlayerFromBet(req.getRoleId());

		if (role != null) {
			if (role.getLine() != req.getLine()) {
				return MmochatUtil.msgbox(req.getHallState(), "您当前正在"
						+ (role.getLine() + 1) + "线活动,请登陆"
						+ (role.getLine() + 1) + "线!");
			}
			// 如果角色在内存中，则要更新竞技点
			try {
				Integer pkScore = MmochatDao.getPkScore(role.getRoleId());
				if (pkScore != null) {
					role.setPk_score(pkScore);
				}
			} catch (EmptyResultDataAccessException e) {
				role.setPk_score(0);
			} catch (Exception e) {
				e.printStackTrace();
			}

			// TODO:如果此角色已经在游戏中了,应作相应清场或重连处理
			role.setDeadConnection(false);
			role.setLastActionTime();
			players.put(role.getRoleId(), role);
			offlinePlayers.remove(role.getRoleId());

			curMap = MmochatMapService.getMapByMapId(role.getMapId());
			if (curMap == null) {
				// 地图不存在,可能之前所在临时地图已经关闭,将其转移到固定地图
				MmochatMapTransPoint newPos = MmochatMap
						.getMapWhenTempMapNotFound(role.getMapId());
				curMap = MmochatMapService.getMapByMapId(newPos
						.getTransToMapId());
				role.setX(newPos.getNewMapX());
				role.setY(newPos.getNewMapY());
				role.setMapId(newPos.getTransToMapId());
			}

			int line = role.getLine();

			// 更新状态
			if (MmochatConstant.isCheckMultiPhoneLogin
					&& !req.getUserConnInfo().equals(role.getUserConnInfo())) {
				// 不是同一个人登陆的
				role.stopDeal();
				MmochatUtil.sendCommonPack(role,
						new Mmochat_ClientVersionError());
			}
			role.setUserConnInfo(req.getUserConnInfo());
			role.setLatestActiveTime(System.currentTimeMillis());
			role.setHasCheckStorePwd(false);

			// 停止交易
			role.stopDeal();

			// 清除周围玩家
			role.getSceenRoles().clear();

			// 清除坐标缓存器
			role.getPositionBuffer().clear();

			// 清除NPC列表
			role.getTmpNpcs().clear();

			// 初始化一些状态
			role.initNormalEnterGame();

			// 下发快捷操作
			CtrlTLVStructureRequest quickStartPack = getQuickStart(req
					.getHallState(), role.getRoleId());
			MmochatUtil.sendCommonPack(role, quickStartPack);

			// 下发团队快捷操作
			CtrlTLVStructureRequest key8Func = getKey8Func(req.getHallState(),
					role.getRoleId());
			MmochatUtil.sendCommonPack(role, key8Func);

			// 下发好友列表
			MmochatFriendService.sendFrindListToPerson(role);

			// 下发商城操作
			CtrlTLVStructureRequest shopTlv = MmochatPropService.getShopTlv(req
					.getHallState(), role.getRoleId());
			MmochatUtil.sendCommonPack(role, shopTlv);

			// 下发包裹
			SendBigPackUtil
					.sendBigPack_5_1S(role, role.getMyPackage().values());

			// 下发我的游戏币数量
			Mmochat_5_31S moneyPack = new Mmochat_5_31S();
			moneyPack.setSmallMoney((int) role.getSmall_money());
			MmochatUtil.sendCommonPack(role, moneyPack);

			// 下发宠物列表
			Mmochat_5_10S petPack = new Mmochat_5_10S();
			petPack.setReset(true);
			petPack.setPets(new ArrayList<MmochatPet>(role.getPets().values()));
			MmochatUtil.sendCommonPack(role, petPack);

			// 下发我的角色信息
			Mmochat_6_2S roleInfoPack = new Mmochat_6_2S();
			roleInfoPack.setPlayer(role);
			MmochatUtil.sendCommonPack(role, roleInfoPack);

			// 下发任务活动信息
			Mmochat_4_4S taskInfoPack = MmochatTaskService
					.getTaskBufferedInfo(role);
			MmochatUtil.sendCommonPack(role, taskInfoPack);

			// 下发驱魔香效果
			Mmochat_1_23S avoidPack = new Mmochat_1_23S();
			avoidPack.setMe(role);
			MmochatUtil.sendCommonPack(role, avoidPack);

			// 进入游戏
			Mmochat_1_1S pack = new Mmochat_1_1S();
			pack.setHallState(req.getHallState());
			pack.setMap(curMap);
			pack.setLine(line);
			pack.setMe(role);
			enterGame(role, req.getUserConnInfo(), pack);
			MmochatUtil.sendCommonPack(role, pack);

			dealDead(role);

			// 如果是在战斗状态,则下发战场
			if (role.isInBattle()) {
				MmochatBattle battle = MmochatBattleService.battles.get(role
						.getBattleId());
				if (battle != null
						&& battle.getState() != MmochatBattleState.战斗即将结束
						&& battle.getState() != MmochatBattleState.战斗结束) {
					Mmochat_3_1S pack11 = new Mmochat_3_1S();
					pack11.setBattle(battle);
					pack11.setMapId(role.getMapId());
					pack11.setLine((byte) role.getLine());
					Byte myPos = battle.getPos(role);
					if (myPos != null) {
						pack11.setMyPos(myPos);
						MmochatPet pet = role.getPetInBattle();
						if (pet != null) {
							Byte petPos = battle.getPos(pet);
							if (petPos != null) {
								pack11.setPetPos(petPos);
							}
						}
						return pack11;
					}
				} else if (battle == null
						|| (battle != null && battle.getState() == MmochatBattleState.战斗结束)) {
					role.leaveBattle();
				}
			}

			// 如果是在观战状态,则下发观战战场
			if (role.isInWatchingBattle()) {
				MmochatBattle battle = MmochatBattleService.battles.get(role
						.getWatchBattleId());
				if (battle != null && !battle.isOver()) {
					Mmochat_3_1S pack11 = new Mmochat_3_1S();
					pack11.setBattle(battle);
					pack11.setMapId(role.getMapId());
					pack11.setLine((byte) role.getLine());
					pack11.setAudience(true);
					pack11.setMyPos((byte) -1);
					return pack11;
				} else {
					role.leaveWatchingBattle();
				}
			}

			// 离线消息
			MmochatFriendService.sendOfflineMsgToPerson(role);

			return null;
		} else {
			// 检查同skyId的其它角色是否已经登陆

			if (req.getRoleId() >= MmochatConstant.guestRoleIdStart
					&& req.getRoleId() < 10000000) {
				// 游客不用检查skyId
			} else {
				for (MmochatPlayer me : players.values()) {
					if (me.getSkyId() == req.getSkyId()
							&& me.getRoleId() != req.getRoleId()) {
						return MmochatUtil.msgbox(req.getHallState(), "您的角色"
								+ MmochatUtil.wrapColor(me.getName(),
										Color.yellow) + "目前正在游戏内活动，请登陆此角色!");
					}
				}
			}

			if (players.size() >= MmochatConstant.maxRolePerServer) {
				return MmochatUtil
						.msgbox(req.getHallState(), "服务器总人数已满,请稍候再进!");
			}

			int lineNum = 0;
			int line = req.getLine();
			for (MmochatMap map : MmochatMapService.maps.values()) {
				if (map != null) {
					lineNum += map.getLineRoleMap(line).size();
				}
			}

			if (lineNum >= MmochatConstant.maxRoleNumPerMapLine) {
				return MmochatUtil
						.msgbox(req.getHallState(), "本线人数已满,请选择其它线路!");
			}

			// 从内存中移除并返回玩家角色
			boolean removeFromQueue = false;
			role = offlinePlayers.remove(req.getRoleId());
			if (role == null) {
				role = MmochatGmService.gmOptionPlayers.remove(req.getRoleId());
				if (role != null) {
					// 如果角色在内存中，则要更新竞技点
					try {
						Integer pkScore = MmochatDao.getPkScore(role
								.getRoleId());
						if (pkScore != null) {
							role.setPk_score(pkScore);
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
				} else {
					role = needToSaveLeaveGameSqlPlayerMap.get(req.getRoleId());
					if (role != null) {
						// 如果角色在内存中，则要更新竞技点
						try {
							Integer pkScore = MmochatDao.getPkScore(role
									.getRoleId());
							if (pkScore != null) {
								role.setPk_score(pkScore);
							}
						} catch (Exception e) {
							e.printStackTrace();
						}
					}
				}
			} else {
				if (!role.isGuest()) {
					offlinePlayers_skyIdMap.remove(role.getSkyId());
				}
				removeFromQueue = true;

				// 如果角色在内存中，则要更新竞技点
				try {
					Integer pkScore = MmochatDao.getPkScore(role.getRoleId());
					if (pkScore != null) {
						role.setPk_score(pkScore);
					}
				} catch (Exception e) {
				}
			}

			if (role == null) {
				try {
					role = MmochatDao.getRole(req.getRoleId());
				} catch (EmptyResultDataAccessException e) {
					return MmochatUtil.msgbox(req.getHallState(),
							"当前角色不存在，如有疑问，请咨询客服电话0571-85222407");
				} catch (Exception e) {
					e.printStackTrace();
					return MmochatUtil.msgbox(req.getHallState(),
							"当前服务器忙,请稍候再试!");
				}
			}

			if (role == null) {
				return MmochatUtil.msgbox(req.getHallState(),
						"当前角色不存在，如有疑问，请咨询客服电话0571-85222407");
			}

			role.setDeadConnection(false);

			if (role.getImei() != null
					&& MmochatConstant.forbiddinImeiList.containsKey(role
							.getImei())) {
				return MmochatUtil.msgbox(req.getHallState(),
						"您由于在游戏中进行了破坏游戏环境的活动，已被禁止进入游戏!"
								+ "如有疑问，请咨询客服电话0571-85222407");
			}

			if (System.currentTimeMillis() < role.getLock_time_point()) {
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
				String t = sdf.format(new Date(role.getLock_time_point()));
				String reason = MmochatGmService.forbiddenReasons.get(role
						.getRoleId());
				String hint = "此角色被冻结，解封时间为" + t + "。";
				if (reason != null && reason.length() > 0) {
					hint += MmochatUtil.wrapColor("原因:" + reason, Color.yellow);
				}
				hint += "(客服电话0571-85222407)";
				if (hint.length() > 200) {
					hint = hint.substring(0, 200);
				}
				return MmochatUtil.msgbox(req.getHallState(), hint);
			}

			// 在不可换线地图，则必需登陆原来的线路
			curMap = MmochatMapService.getMapByMapId(role.getMapId());
			if (curMap != null && !curMap.isCanChangeLine()) {
				if (req.getLine() != role.getLine()) {
					role.setLatestActiveTime(System.currentTimeMillis());
					offlinePlayers.put(role.getRoleId(), role);
					return MmochatUtil.msgbox(req.getHallState(),
							"您所在地图为不可换线地图，请登陆" + (role.getLine() + 1)
									+ "线进入此地图!");
				}
			}

			if (lineNum >= MmochatConstant.maxNormalRoleNumPerLine) {
				if (!role.hasPropEffect(MmochatPropType.会员周卡.getEffectKey())) {
					role.setLatestActiveTime(System.currentTimeMillis());
					offlinePlayers.put(role.getRoleId(), role);
					return MmochatUtil.msgbox(req.getHallState(),
							"本线人数拥挤,请选择其它线路!会员可以不受限制进入拥挤线路。");
				}
			}

			if (removeFromQueue) {
				needToSaveLeaveGameSqlPlayerMap.remove(role.getRoleId());
			}

			MmochatStatisticsService.todayLoginNum.put(role.getRoleId(),
					(byte) 0);

			// 初始化一些状态
			role.initNormalEnterGame();
			role.setHasCheckStorePwd(false);

			if (curMap == null) {
				// 地图不存在,可能之前所在临时地图已经关闭,将其转移到固定地图
				MmochatMapTransPoint newPos = MmochatMap
						.getMapWhenTempMapNotFound(role.getMapId());
				curMap = MmochatMapService.getMapByMapId(newPos
						.getTransToMapId());
				role.setX(newPos.getNewMapX());
				role.setY(newPos.getNewMapY());
				role.setMapId(newPos.getTransToMapId());
			}

			// 给新手增加新手任务
			if (role.getLogin_time() == 0) {
				role.setUserConnInfo(req.getUserConnInfo());

				MmochatTask hintTask = new MmochatTask();
				hintTask.setTaskId(90001);
				hintTask.setTaskName("指引任务");
				hintTask.setTaskDetail("找小雅了解情况!靠近小雅,按中间键或触屏点她就能发起对话噢。");
				hintTask.setTaskType(MmochatTaskType.过渡任务);
				hintTask.setTaskState(MmochatTaskStateType.已接);
				hintTask.setFinish_npcId(75);// 小雅NPCID
				role.addTask(hintTask);

				MmochatNpc targetNpc = MmochatNpcService.getNpcById(75);
				if (targetNpc != null) {
					Mmochat_4_9S pack = new Mmochat_4_9S();
					pack.setMapId(targetNpc.getMapId());
					pack.setX(targetNpc.getX());
					pack.setY(targetNpc.getY());
					MmochatUtil.sendCommonPack(role, pack);
				}

				// 血蓝加满
				role.setCurBlood(role.getTotalBlood());
				role.setCurSprit(role.getTotalSprit());

				// 屏弊其它玩家
				role.setShowRoleSet(MmochatShowRoleSet.隐藏所有人);
				Mmochat_1_20S pack = new Mmochat_1_20S();
				pack.setShowRoleSetValue(MmochatShowRoleSet.隐藏所有人.getValue());
				MmochatUtil.sendCommonPack(role, pack);
			}
			role.addLogin_time();
			role.setLine(line);

			Mmochat_1_1S pack = new Mmochat_1_1S();
			pack.setHallState(req.getHallState());
			pack.setMap(curMap);
			pack.setLine(line);
			pack.setMe(role);

			// 第一次进游戏处理
			if (role.getLogin_time() <= 1) {

				// 初始包裹格子
				role.initWhenFirstTimeLogin();

				// 赠送新手装备
				int equipLevel = 0;
				MmochatEquip equip = MmochatEquipService.createRandomEquip(
						true, MmochatEquipType.头盔, equipLevel,
						MmochatEquipQualityType.白装);
				equip.setCanDeal(false);
				MmochatPackageGrid grid = role.getMyPackage().get(
						MmochatEquipPlaceType.头部.getValue());
				grid.setObject(equip);

				equip = MmochatEquipService.createRandomEquip(true,
						MmochatEquipType.武器, equipLevel,
						MmochatEquipQualityType.白装);
				equip.setCanDeal(false);
				grid = role.getMyPackage().get(
						MmochatEquipPlaceType.手上.getValue());
				grid.setObject(equip);

				equip = MmochatEquipService.createRandomEquip(true,
						MmochatEquipType.衣服, equipLevel,
						MmochatEquipQualityType.白装);
				equip.setCanDeal(false);
				grid = role.getMyPackage().get(
						MmochatEquipPlaceType.身体.getValue());
				grid.setObject(equip);

				equip = MmochatEquipService.createRandomEquip(true,
						MmochatEquipType.鞋子, equipLevel,
						MmochatEquipQualityType.白装);
				equip.setCanDeal(false);
				grid = role.getMyPackage().get(
						MmochatEquipPlaceType.脚.getValue());
				grid.setObject(equip);

				// 赠送新手礼包
				MmochatProp prop = new MmochatProp(MmochatPropType.十级大礼包);
				prop.setCanDrop(false);
				prop.setCanDeal(false);
				role.addObjectToPackage(prop, false);

				// 赠送推荐人奖励
				if (role.getSuggestName() != null
						&& role.getSuggestName().length() > 0) {
					// 5个天尊令和1个神行法宝残片
					prop = new MmochatProp(MmochatPropType.天尊令);
					prop.setCanDeal(false);
					prop.setOverlapNum(5);
					role.addObjectToPackage(prop, false);
					prop = new MmochatProp(MmochatPropType.神行法宝残片);
					prop.setCanDeal(false);
					role.addObjectToPackage(prop, false);
					MmochatChatService.sendSystemMsgToPerson(role,
							"由于您填写了推荐人，获得了5个天尊令和1个神行法宝残片，按3键查看!");
				}

				// 设置满血
				role.setCurBlood(role.getTotalBlood());
				role.setCurSprit(role.getTotalSprit());

				// 下发新手提示
				pack.setEnterMapMsg("请按"
						+ MmochatUtil.wrapColor("中间键", Color.yellow) + "向"
						+ MmochatUtil.wrapColor("小雅", Color.green)
						+ "接受指引任务(或者触屏点击小雅)。");

				// 保存数据库:包裹、登陆次数、任务、仓库
				try {
					MmochatDao.updateRoleFirstEnterGame(role);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

			Date now = new Date();

			long lastLoginTime = role.getLatest_login_time();
			long offlineTime = role.getLatest_offline_time(); // 如果上次服务器直接关掉，则此项值是上上次离线时间

			if (offlineTime == 0) {
				offlineTime = now.getTime();
			}
			if (lastLoginTime == 0) {
				lastLoginTime = now.getTime();
			}

			// 更新使用中的神行法宝的灵气
			if (role.getMyPackage() != null) {
				MmochatPackageGrid grid1 = role.getMyPackage().get(
						MmochatSuperMachineType.神行法宝.getGridId());
				if (grid1 != null && grid1.getObject() != null) {
					MmochatCommonObject superMachine = grid1.getObject();
					// 检查神行法宝是否已经满级
					int curSpeedLevel = superMachine.getFlyMachineSpeedLevel();
					int curFlyLevel = superMachine.getFlyMachineFlyLevel();
					if (curSpeedLevel == MmochatCommonObject.flyMachineMaxSpeedLevel
							&& curFlyLevel == MmochatCommonObject.flyMachineMaxFlyLevel) {
						// 满级，不再增加灵气
					} else {
						if (superMachine.getOwnerState() == MmochatObjOwnerState.未认主) {
							String enterMsg = "您的神行法宝未认主,无法根据在线时间获得灵气!";
							pack.setEnterMapMsg(enterMsg);
						} else {
							// 根据上次在线时间、离线时间，计算并增加神行法宝灵气
							// 在线5分钟，涨1点灵气；离线30分钟涨1点灵气
							int totalValue = 0;
							long lastOnlineTime = Math.max(0, offlineTime
									- lastLoginTime);
							long onlineMin = lastOnlineTime
									/ MmochatConstant.MS_PER_MINUTE;
							if (onlineMin > 0) {
								totalValue += onlineMin / 5;
							}
							long lastOfflineTime = Math.max(0, now.getTime()
									- offlineTime);
							long offlineMin = lastOfflineTime
									/ MmochatConstant.MS_PER_MINUTE;
							if (offlineMin > 0) {
								totalValue += offlineMin / 30;
							}
							if (totalValue > 200) {
								totalValue = 200;
							}
							if (totalValue > 0) {
								superMachine.addFlyMachineExp(totalValue);
								String enterMsg = "您上一次在线时长"
										+ onlineMin
										+ "分钟(5分钟1点灵气),离线时长"
										+ offlineMin
										+ "分钟(30分钟1点灵气),在这期间,您的神行法宝获得了"
										+ MmochatUtil.wrapColor(totalValue,
												Color.green) + "点灵气(上限200点)!";
								pack.setEnterMapMsg(enterMsg);
							}
						}
					}
				}
			}
			// 更新包裹中的神行法宝体力
			if (role.getMyPackage() != null) {
				for (MmochatPackageGrid grid : role.getMyPackage().values()) {
					if (grid != null && grid.getObject() != null) {
						if (grid.getObject().getType() == MmochatSuperMachineType.神行法宝) {
							MmochatCommonObject superMachine = grid.getObject();
							// 更新法宝体力
							if (superMachine.getFlyMachineCanUseTotalValue() > 0) {
								long lastTime = now.getTime()
										- superMachine
												.getFlyMachineUseStartTime();
								if (lastTime > 0) {
									long hour = lastTime
											/ MmochatConstant.MS_PER_HOUR;
									long useValue = hour
											* MmochatCommonObject
													.getFlyMachineUsePerHour(
															superMachine
																	.getFlyMachineSpeedLevel(),
															superMachine
																	.getFlyMachineFlyLevel());
									long restValue = superMachine
											.getFlyMachineCanUseTotalValue()
											- useValue;
									if (restValue <= 0) {
										// 体力用光
										superMachine
												.setFlyMachineCanUseTotalValue(0);
										superMachine
												.setFlyMachineCanUseValue(0);
										superMachine
												.setFlyMachineUseStartTime(now
														.getTime());
									} else {
										superMachine
												.setFlyMachineCanUseValue(restValue);
									}
								}
							}
						}
					}
				}
			}

			// 更新仓库中的神行法宝体力
			if (role.getMyStorage() != null) {
				for (MmochatPackageGrid grid : role.getMyStorage().values()) {
					if (grid != null && grid.getObject() != null) {
						if (grid.getObject().getType() == MmochatSuperMachineType.神行法宝) {
							MmochatCommonObject superMachine = grid.getObject();
							// 更新法宝体力
							if (superMachine.getFlyMachineCanUseTotalValue() > 0) {
								long lastTime = now.getTime()
										- superMachine
												.getFlyMachineUseStartTime();
								if (lastTime > 0) {
									long hour = lastTime
											/ MmochatConstant.MS_PER_HOUR;
									long useValue = hour
											* MmochatCommonObject
													.getFlyMachineUsePerHour(
															superMachine
																	.getFlyMachineSpeedLevel(),
															superMachine
																	.getFlyMachineFlyLevel());
									long restValue = superMachine
											.getFlyMachineCanUseTotalValue()
											- useValue;
									if (restValue <= 0) {
										// 体力用光
										superMachine
												.setFlyMachineCanUseTotalValue(0);
										superMachine
												.setFlyMachineCanUseValue(0);
										superMachine
												.setFlyMachineUseStartTime(now
														.getTime());
									} else {
										superMachine
												.setFlyMachineCanUseValue(restValue);
									}
								}
							}
						}
					}
				}
			}

			// try {
			// // 此处更新了登陆时间
			// MmochatDao.updateRoleEnterGame(role, line);
			// } catch (Exception e) {
			// e.printStackTrace();
			// return MmochatUtil.msgbox(req.getHallState(), "当前服务器忙,请稍候再试!");
			// }

			enterGame(role, req.getUserConnInfo(), pack);

			role.setLatest_login_time(now.getTime());
			// 判断本次登陆与上次离线是否为同一天，如果不是，则增加本月登陆天数次数
			Date lastOfflineDate = new Date(offlineTime);
			if (now.getYear() == lastOfflineDate.getYear()
					&& now.getMonth() == lastOfflineDate.getMonth()
					&& now.getDate() == lastOfflineDate.getDate()) {
				// 同一天
			} else {
				role.addCur_month_login_day_num(1);
			}

			// 如果今天还没领奖，则提示领奖券
			Date lastDate = new Date(role.getLastLotteryTime());
			if (now.getDate() == lastDate.getDate()
					&& now.getMonth() == lastDate.getMonth()
					&& now.getYear() == lastDate.getYear()) {
				// 今天已领
			} else {
				if (role.getLogin_time() > 1) {
					String info;
					info = "您可以到"
							+ MmochatUtil
									.wrapColor("余杭(1036,822)", Color.green)
							+ "找" + MmochatUtil.wrapColor("奖券仙女", Color.green)
							+ "领取奖券!";
					info += MmochatUtil.wrapColor("设置钱庄密码后可额外领取100~300天道行!",
							Color.magenta);

					CreateMsgBoxTLV msgbox = new CreateMsgBoxTLV();
					msgbox.setContent(new Text(info));
					msgbox.setLeftName("领取");
					msgbox.setRightName("取消");
					TLVStructure tlv = MmochatNpcService
							.getNpcTlvWin(role, 305);
					if (tlv != null) {
						msgbox.addLeftTLV(tlv);
					}
					CtrlTLVStructureRequest tlvPack = new CtrlTLVStructureRequest(
							0, msgbox);
					tlvPack.setSrcId(MmochatMain.getModuleInstID());
					tlvPack.setDstId(MmochatConstant.getClientModuleId());
					tlvPack.setMsgCode(MmochatConstant.MSGCODE_MMOCHAT_S_10_20);
					MmochatUtil.sendCommonPack(role, tlvPack);
				}
			}

			// 老用户回归活动：60级以上30天未登陆的获得一个大礼包
			if (MmochatConstant.isPlayerCallBackActivityOpen) {
				// 2月9号至2月15号开放
				if (now.getMonth() == 1 && now.getDate() >= 9
						&& now.getDate() <= 15) {
					if (role.getLevel() >= 60) {
						long interval = (System.currentTimeMillis() - offlineTime)
								/ MmochatConstant.MS_PER_DAY;
						if (interval >= 30) {
							if (role.hasEnoughPackageSpace(1)) {
								MmochatProp prop = new MmochatProp(
										MmochatPropType.老用户回归大礼包);
								prop.setCanDeal(false);
								role.addObjectToPackage(prop, false);
								try {
									MmochatDao.updateMyPackage(role);
								} catch (Exception e) {
									e.printStackTrace();
								}
								String info = MmochatUtil
										.wrapColor(
												"您获得了系统赠送给您的一份"
														+ MmochatUtil
																.wrapColor(
																		MmochatPropType.老用户回归大礼包
																				.toString(),
																		Color.yellow)
														+ "，请按3键查看包裹!欢迎您回到仙剑问情。",
												Color.red);
								MmochatFriendService
										.sendSystemMsgToPersonByFriendMessage(
												role, info);

								MmochatChatService.sendSystemMsg(MmochatUtil
										.wrapColor(role.getName(), Color.green)
										+ "满世界转了一圈，又重新回到了仙剑问情，和久别的朋友们一起仗剑江湖!");
							} else {
								// 尝试放到仓库中
								MmochatProp prop = new MmochatProp(
										MmochatPropType.老用户回归大礼包);
								prop.setCanDeal(false);
								boolean ret = role.addObjectToStorage(prop);
								if (ret) {
									try {
										MmochatDao.updateMyStorage(role);
									} catch (Exception e) {
										e.printStackTrace();
									}
									String info = MmochatUtil
											.wrapColor(
													"您获得了系统赠送给您的一份"
															+ MmochatUtil
																	.wrapColor(
																			MmochatPropType.老用户回归大礼包
																					.toString(),
																			Color.yellow)
															+ "，请到钱庄查收!欢迎您回到仙剑问情。",
													Color.red);
									MmochatFriendService
											.sendSystemMsgToPersonByFriendMessage(
													role, info);

									MmochatChatService
											.sendSystemMsg(MmochatUtil
													.wrapColor(role.getName(),
															Color.green)
													+ "满世界转了一圈，又重新回到了仙剑问情，和久别的朋友们一起仗剑江湖!");
								}
							}
						}
					}
				}
			}

			role.setLatest_offline_time(now.getTime());

			// 如果是昨天注册的，则增加统计
			Date regTime = new Date(role.getCreateTime());
			regTime.setHours(0);
			regTime.setMinutes(0);
			regTime.setSeconds(1);
			Date curTime = new Date();
			curTime.setHours(0);
			curTime.setMinutes(0);
			curTime.setSeconds(1);
			if (curTime.getTime() - regTime.getTime() >= MmochatConstant.MS_PER_DAY - 10000
					&& curTime.getTime() - regTime.getTime() <= MmochatConstant.MS_PER_DAY + 10000) {
				MmochatStatisticsService.todayLoginNumOfYesterdayRegMap.put(
						role.getRoleId(), (byte) 0);
			}

			// 下发快捷操作
			CtrlTLVStructureRequest quickStartPack = getQuickStart(req
					.getHallState(), role.getRoleId());
			MmochatUtil.sendCommonPack(role, quickStartPack);

			// 下发团队快捷操作
			CtrlTLVStructureRequest key8Func = getKey8Func(req.getHallState(),
					role.getRoleId());
			MmochatUtil.sendCommonPack(role, key8Func);

			// 下发好友列表
			MmochatFriendService.sendFrindListToPerson(role);

			// 下发商城操作
			CtrlTLVStructureRequest shopTlv = MmochatPropService.getShopTlv(req
					.getHallState(), role.getRoleId());
			MmochatUtil.sendCommonPack(role, shopTlv);

			// 下发驱魔香效果
			Mmochat_1_23S avoidPack = new Mmochat_1_23S();
			avoidPack.setMe(role);
			MmochatUtil.sendCommonPack(role, avoidPack);

			// 通知好友我上线了
			for (Integer roleId1 : role.getMyFans().values()) {
				MmochatPlayer friend = players.get(roleId1);
				if (friend == null) {
					continue;
				}
				MmochatFriend friendShip = friend.getMyDearFriends().get(
						role.getRoleId());
				if (friendShip == null) {
					// 在我离线期间，这位好友将我删出好友了
					role.delFans(roleId1);
				} else {
					// 上线消息
					friendShip.setBmpId(role.getBmpId());
					friendShip.setName(role.getName());
					friendShip.setMoodInfo(role.getMoodInfo());

					friend.addOnlineFriend(role.getRoleId());

					if (friend.getMyIdols().containsKey(role.getRoleId())) {
						MmochatChatService.sendSystemMsgToPerson(friend, "您的好友"
								+ MmochatUtil.wrapColor(role.getName(),
										Color.green) + "上线了!");
					}
				}
			}

			role.stopDeal();

			// 兼容操作：检查包裹装备版本号
			// 兼容操作：将包裹中的吸属过的白水晶转为黑水晶
			boolean needUpdatePackage = false;
			for (MmochatPackageGrid grid : role.getMyPackage().values()) {
				if (grid != null) {
					MmochatCommonObject obj = grid.getObject();
					if (obj != null) {
						if (obj.getObjectType() == MmochatObjectType.装备) {
							if (obj.getEquipVersion() == null
									|| obj.getEquipVersion() != MmochatEquipVersion.V20111108) {
								// 不是最新版本的装备，装备升级
								MmochatCommonObject newObj = MmochatEquipService
										.updateEquipToV20111108(obj);
								if (newObj != null) {
									grid.setObject(newObj);
									needUpdatePackage = true;
								}
							}
						} else if (obj.getPropType() != null) {
							if (obj.getPropType() == MmochatPropType.白水晶
									|| obj.getPropType() == MmochatPropType.超级白水晶) {
								if (obj.getEquipAttrInProp() != null) {
									// 吸属过了
									obj.setPropType(MmochatPropType.黑水晶);
									obj.setCanOverlap(MmochatPropType.黑水晶
											.isCanOverLap());
									needUpdatePackage = true;
								} else if (!obj.isCanOverlap()) {
									// 未吸属，不可叠加
									obj.setCanOverlap(obj.getPropType()
											.isCanOverLap());
									needUpdatePackage = true;
								}
							}
						}
					}
				}
			}

			if (needUpdatePackage) {
				// 保存包裹数据库
				try {
					MmochatDao.updateMyPackage(role);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

			// 兼容操作：检查仓库装备版本号
			// 兼容操作：将仓库中的吸属过的白水晶转为黑水晶
			boolean needUpdateStorage = false;
			for (MmochatPackageGrid grid : role.getMyStorage().values()) {
				if (grid != null) {
					MmochatCommonObject obj = grid.getObject();
					if (obj != null) {
						if (obj.getObjectType() == MmochatObjectType.装备) {
							if (obj.getEquipVersion() == null
									|| obj.getEquipVersion() != MmochatEquipVersion.V20111108) {
								// 不是最新版本的装备，装备升级
								MmochatCommonObject newObj = MmochatEquipService
										.updateEquipToV20111108(obj);
								if (newObj != null) {
									grid.setObject(newObj);
									needUpdateStorage = true;
								}
							}
						} else if (obj.getPropType() != null) {
							if (obj.getPropType() == MmochatPropType.白水晶
									|| obj.getPropType() == MmochatPropType.超级白水晶) {
								if (obj.getEquipAttrInProp() != null) {
									// 吸属过了
									obj.setPropType(MmochatPropType.黑水晶);
									obj.setCanOverlap(MmochatPropType.黑水晶
											.isCanOverLap());
									needUpdateStorage = true;
								} else if (!obj.isCanOverlap()) {
									// 未吸属，不可叠加
									obj.setCanOverlap(obj.getPropType()
											.isCanOverLap());
									needUpdateStorage = true;
								}
							}
						}
					}
				}
			}
			if (needUpdateStorage) {
				try {
					MmochatDao.updateMyStorage(role);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

			// 下发包裹
			SendBigPackUtil
					.sendBigPack_5_1S(role, role.getMyPackage().values());

			// 下发我的游戏币数量
			Mmochat_5_31S moneyPack = new Mmochat_5_31S();
			moneyPack.setSmallMoney((int) role.getSmall_money());
			MmochatUtil.sendCommonPack(role, moneyPack);

			// 兼容操作：检查参战宠物是否有超过人物10级的
			boolean needUpdatePet = false;
			for (MmochatPet pet : role.getPets().values()) {
				if (pet != null) {
					if (pet.getLevel() > role.getLevel()
							+ MmochatConstant.maxPetLevelMoreThanOwner) {
						// 宠物高于人物等级，则设置未参战
						if (pet.getState() == MmochatPetStateType.参战
								|| pet.getState() == MmochatPetStateType.替补) {
							pet.setState(MmochatPetStateType.休息);
							needUpdatePet = true;
						}
					}
				}
			}
			if (needUpdatePet) {
				try {
					MmochatDao.updateRolePets(role);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

			// 下发宠物列表
			Mmochat_5_10S petPack = new Mmochat_5_10S();
			petPack.setReset(true);
			petPack.setPets(new ArrayList<MmochatPet>(role.getPets().values()));
			MmochatUtil.sendCommonPack(role, petPack);

			// 兼容操作：修正血石效果
			{
				// 原血石effectId=1093,1094,1095，全部改为1011，与原血池一致
				long total = 0;
				MmochatPropEffect effect = role.getPropEffects().get(1093);
				if (effect != null) {
					total += effect.getRestAmount();
					effect.setRestAmount(0);
					role.getPropEffects().remove(1093);
				}

				effect = role.getPropEffects().get(1094);
				if (effect != null) {
					total += effect.getRestAmount();
					effect.setRestAmount(0);
					role.getPropEffects().remove(1094);
				}

				effect = role.getPropEffects().get(1095);
				if (effect != null) {
					total += effect.getRestAmount();
					effect.setRestAmount(0);
					role.getPropEffects().remove(1095);
				}
				if (total > 0) {
					effect = role.getPropEffects().get(
							MmochatPropType.小血池.getEffectKey());
					if (effect != null) {
						effect.addAmount(total);
					} else {
						effect = new MmochatPropEffect();
						effect.setPropType(MmochatPropType.小血池);
						effect.setRestAmount(total);
						role.addPropEffect(effect);
					}
				}
			}

			// 兼容操作:如果不是守护/门派最强，但有相应称号，则去除称号
			try {
				boolean needUpdateChenhao = false;
				for (MmochatMap map : MmochatMapService.maps.values()) {
					if (map != null) {
						MmochatMapGuider guiderInfo = map.getMapGuiderInfo();
						if (guiderInfo == null) {
							continue;
						}
						switch (guiderInfo.getType()) {
						case 地图守护神: {
							MmochatChenHaoType chenhaoType = MmochatChenHaoType
									.valueOf(map.getMapName() + "守护神");
							if (role.getChenHaoMap().containsKey(chenhaoType)) {
								// 有此守护神称号，检查是否是在位守护神
								boolean hasChenhao = false;
								MmochatMapGuiderData guider = MmochatMapGuiderService.guiderPositions
										.get(map.getMapId());
								if (guider != null) {
									if (guider.isOnDudy()
											&& guider.getRoleList() != null
											&& guider.getRoleList().contains(
													(Integer) role.getId())) {
										hasChenhao = true;
									}
								}
								if (!hasChenhao) {
									// 这个称号不应该有
									role.getChenHaoMap().remove(chenhaoType);
									needUpdateChenhao = true;
								}
							}
							break;
						}
						case 门派最强: {
							MmochatChenHaoType chenhaoType = MmochatChenHaoType
									.valueOf(map.getMapName() + "最强");
							if (role.getChenHaoMap().containsKey(chenhaoType)) {
								// 有此称号，检查是否是在位
								boolean hasChenhao = false;
								MmochatMapGuiderData guider = MmochatMapGuiderService.familyGuiderPositions
										.get(map.getMapId());
								if (guider != null) {
									if (guider.isOnDudy()
											&& guider.getRoleList() != null
											&& guider.getRoleList().contains(
													(Integer) role.getId())) {
										hasChenhao = true;
									}
								}
								if (!hasChenhao) {
									// 这个称号不应该有
									role.getChenHaoMap().remove(chenhaoType);
									needUpdateChenhao = true;
								}
							}
							break;
						}
						default:
							break;
						}
					}
				}
				if (needUpdateChenhao) {
					try {
						MmochatDao.saveChenhao(role);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}

			// 下发我的角色信息
			Mmochat_6_2S roleInfoPack = new Mmochat_6_2S();
			roleInfoPack.setPlayer(role);
			MmochatUtil.sendCommonPack(role, roleInfoPack);

			// 下发任务活动信息
			Mmochat_4_4S taskInfoPack = MmochatTaskService
					.getTaskBufferedInfo(role);
			MmochatUtil.sendCommonPack(role, taskInfoPack);

			// 系统公告
			// 公告放到#键系统消息里
			try {
				List<MmochatAnnouncement> infoList = MmochatServerListService
						.getValidAnnouncement(role);
				if (infoList != null && infoList.size() > 0) {
					CreateTlvWin tlv = new CreateTlvWin();
					tlv.setWinType(WinType.List);
					tlv.setLeftName("详情");
					tlv.setRightName("关闭");
					tlv.setTitle(infoList.size() + "条系统公告");
					tlv.setWinHeight(208);
					tlv.addRightTLV(new CloseWinTLV());

					for (MmochatAnnouncement info : infoList) {
						String item;
						if (info.getTitleColor() != null) {
							item = MmochatUtil.wrapColor(info.getTitle(), info
									.getTitleColor());
						} else {
							item = info.getTitle();
						}
						tlv.addItemEvent(item, new ClearDataTLV(),
								new AddDataTLV((int) info.getId()));
					}
					tlv.addLeftTLV(new SendDataTLV(MmochatConstant
							.getClientModuleId(),
							MmochatMain.getModuleInstID(),
							MmochatConstant.MSGCODE_MMOCHAT_C_1_35, null));
					tlv.addLeftTLV(new ShowWaitingMsgBoxTLV());

					CtrlTLVStructureRequest AnnouncementPack = new CtrlTLVStructureRequest(
							0, tlv);
					AnnouncementPack.setSrcId(MmochatMain.getModuleInstID());
					AnnouncementPack.setDstId(MmochatConstant
							.getClientModuleId());
					AnnouncementPack
							.setMsgCode(MmochatConstant.MSGCODE_MMOCHAT_S_10_20);
					MmochatUtil.sendCommonPack(role, AnnouncementPack);
				}
			} catch (Exception e2) {
				e2.printStackTrace();
			}

			// if (announcement != null && announcement.length() > 0) {
			// if (pack.getEnterMapMsg() == null) {
			// // 如果没有对话框，则直接弹出公告
			// pack.setEnterMapText(announcement);
			// } else {
			// // 如果有对话框，则公告放到#键系统消息里
			// CreateTlvWin tlv = new CreateTlvWin();
			// tlv.setWinType(WinType.Text);
			// tlv.setRightName("返回");
			// tlv.setTitle("系统公告");
			// tlv.setWinHeight(188);
			// tlv.addRightTLV(new CloseWinTLV());
			// tlv.setContent(new Text(announcement));
			//
			// CtrlTLVStructureRequest AnnouncementPack = new
			// CtrlTLVStructureRequest(
			// 0, tlv);
			// AnnouncementPack.setSrcId(MmochatMain.getModuleInstID());
			// AnnouncementPack.setDstId(MmochatConstant
			// .getClientModuleId());
			// AnnouncementPack
			// .setMsgCode(MmochatConstant.MSGCODE_MMOCHAT_S_10_20);
			// MmochatUtil.sendCommonPack(role, AnnouncementPack);
			// }
			// }

			MmochatUtil.sendCommonPack(role, pack);

			// 如果有战斗的额外奖励抽奖，则下发抽奖
			{
				List<MmochatExtraRandomAward> list = MmochatBattleService.battleExtraAward
						.get(role.getRoleId());
				if (list != null && list.size() > 0) {
					for (MmochatExtraRandomAward extra : list) {
						if (!extra.isSent()
								&& extra.getRoleId() == role.getRoleId()) {
							CreateTlvWin tlv = new CreateTlvWin();
							tlv.setWinType(WinType.List);
							tlv.setLeftName("打开");
							tlv.setTitle("选择一个宝箱打开");
							tlv.setWinHeight(228);
							tlv.setRightName("返回");
							tlv.addRightTLV(new CloseWinTLV());

							tlv.addItemEvent("道行奖励宝箱一");
							tlv.addItemEvent("道行奖励宝箱二");
							tlv.addItemEvent("道行奖励宝箱三");
							tlv.addItemEvent("道行奖励宝箱四");
							tlv.addItemEvent("道行奖励宝箱五");
							tlv.addItemEvent("道行奖励宝箱六");
							tlv.addItemEvent("道行奖励宝箱七");
							tlv.addItemEvent("道行奖励宝箱八");
							tlv.addItemEvent("道行奖励宝箱九");
							tlv.addItemEvent("道行奖励宝箱十");
							tlv.addLeftTLV(new ClearDataTLV());
							tlv.addLeftTLV(new AddDataTLV((int) extra.getId()));
							tlv.addLeftTLV(new SendDataTLV(MmochatConstant
									.getClientModuleId(), MmochatMain
									.getModuleInstID(),
									MmochatConstant.MSGCODE_MMOCHAT_C_3_15,
									(int) role.getRoleId()));
							ShowWaitingMsgBoxTLV wait = new ShowWaitingMsgBoxTLV();
							wait.setShowCancel(false);
							tlv.addLeftTLV(wait);

							CtrlTLVStructureRequest awardPack = new CtrlTLVStructureRequest(
									0, tlv);
							awardPack.setSrcId(MmochatMain.getModuleInstID());
							awardPack.setDstId(MmochatConstant
									.getClientModuleId());
							awardPack
									.setMsgCode(MmochatConstant.MSGCODE_MMOCHAT_S_10_20);
							MmochatUtil.sendCommonPack(role, awardPack);
							break;
						}
					}
				}
			}

			// 下发欢迎提示语
			int hour = now.getHours();
			int min = now.getMinutes();
			String time = hour + ":";
			if (min < 10) {
				time += "0" + min;
			} else {
				time += min;
			}
			String msg;
			if (hour >= 5 && hour <= 8) {
				msg = "早上好,";
			} else if (hour > 8 && hour < 11) {
				msg = "上午好,";
			} else if (hour >= 11 && hour < 14) {
				msg = "中午好,";
			} else if (hour >= 14 && hour < 19) {
				msg = "下午好,";
			} else {
				msg = "晚上好,";
			}
			MmochatChatService.sendSystemMsgToPerson(role, msg + role.getName()
					+ ".现在是" + time);
			if (MmochatNpcService.famousList.get(role.getRoleId()) != null) {
				MmochatChatService.sendSystemMsgToPerson(role, "恭喜!您已荣登排行榜!");
			}
			if (MmochatSystemState.isSystemDoubleAward()) {
				// 系统双倍时间
				MmochatChatService.sendSystemMsgToPerson(role,
						"现在是系统双倍时间，打怪、刷道都是双倍奖励噢!");
			}

			if (MmochatPropService.payLotteryInfo != null
					&& MmochatPropService.payLotteryInfo.getState() == MmochatPayLotteryState.开始统计) {
				// 限时充值抽大奖活动
				MmochatChatService.sendSystemMsgToPerson(role,
						"现在正在进行限时充值抽大奖活动，按9键进入<充值元宝>查看详情!");
			}

			// 如果有客服消息，则下发客服消息
			for (MmochatKefuQuestion question : MmochatGmService.kefuMsg) {
				if (question.isReplied()
						&& question.getRoleId() == role.getRoleId()) {
					// 问题已答复，下发给玩家
					String content = question.getLastContent();
					if (content == null) {
						continue;
					}
					MmochatGmService.sendKefuMesboxToPerson(role, question
							.getId(), content, question.isNeedReply());
				}
			}

			if (role.getLogin_time() <= 1) {
				String info = "";
				if (MmochatMain.getServerName() != null) {
					info = "欢迎{fromSkyid}加入${appName}$-"
							+ MmochatMain.getServerName() + "区!";
				} else {
					info = "欢迎{fromSkyid}加入${appName}$!";
				}
				MmochatFeedService.addFeed(req.getSkyId(), info);
			}

			dealDead(role);

			// 检查道具是否过期
			MmochatPropService.checkRoleProp(role);

			// 检查是否有称号过期
			for (MmochatChenHao chenhao : role.getChenHaoMap().values()) {
				if (chenhao.isTimeOut()) {
					MmochatChenHao.delAndUpdateChenHaoAndSaveSql(role
							.getRoleId(), chenhao.getType());
				}
			}

			// 离线消息
			MmochatFriendService.sendOfflineMsgToPerson(role);

			// 判断解除认主物品是否已解
			MmochatEquipService.updateOwnerStateForPlayer(role);

			// 如果有解除中的物品，进行解除提醒
			MmochatEquipService.checkOwnerStateForPlayer(role);

			// 如果密码正在清除中，进行提醒
			if (role.getStore_pwd_state() == MmochatStorePwdState.清除钱庄密码中) {
				long rest = MmochatConstant.releaseStorePwdInterval
						- (System.currentTimeMillis() - role
								.getReleaseStorePwdTime());
				if (rest < 0) {
					// 正式解除
					try {
						MmochatDao.updateStorePwd("",
								MmochatStorePwdState.未设置钱庄密码.getValue(), 0,
								role.getRoleId());
					} catch (Exception e) {
						e.printStackTrace();
					}
					role.setStore_pwd_state(MmochatStorePwdState.未设置钱庄密码);
					MmochatFriendService.sendSystemMsgToPersonByFriendMessage(
							role, "您的钱庄密码已解除!请注意账号安全，设置新的钱庄密码。");
				} else {
					int day = (int) (rest / MmochatConstant.MS_PER_DAY);
					int h = (int) ((rest - day * MmochatConstant.MS_PER_DAY) / MmochatConstant.MS_PER_HOUR);
					String t = "";
					if (day > 0) {
						t += day + "天";
					}
					t += h + "小时";
					String hint = MmochatUtil.wrapColor("您已经申请清除钱庄密码",
							Color.red)
							+ "，密码将在"
							+ MmochatUtil.wrapColor(t, Color.green)
							+ "后正式清除。" + "如果这不是您自己申请的操作，请立即修改账号密码，并中止清除钱庄密码。";
					MmochatFriendService.sendSystemMsgToPersonByFriendMessage(
							role, hint);
				}
			}

			if (MmochatPropService.canTakeFirstPayAward(role)) {
				// 首次充值活动
				String info = MmochatUtil.wrapColor("首次充值送豪礼", Color.magenta)
						+ "活动开始啦!您只要在"
						+ MmochatSystemState.getFirstPay_timeInfo()
						+ "期间，按9键充值元宝，进行K币兑换或充值卡充值，即可获得"
						+ MmochatUtil.wrapColor(MmochatSystemState
								.getFirstPay_daoAward()
								+ "年道行、"
								+ MmochatSystemState.getFirstPay_expAward()
								+ "次打怪经验", Color.red) + "!一生只有一次的机会!";
				info = MmochatUtil.wrapColor(info, Color.yellow);
				MmochatFriendService.sendMsgToPersonByFriendMessage(role, info);
				MmochatChatService.sendSystemMsgToPerson(role, info);
			}

			// 即开型充值抽奖
			if (MmochatPropService.fastPayLotteryInfo != null
					&& MmochatPropService.fastPayLotteryInfo.getState() == MmochatPayLotteryState.开始统计) {
				// 系统公告
				String sysInfo = MmochatPropService.fastPayLotteryInfo
						.getStartMsg();
				if (sysInfo != null) {
					MmochatChatService.sendSystemMsgToPerson(role, sysInfo);
				}
			}

			// 经验冻结丹到期提醒
			try {
				MmochatPropEffect propEffect = role.getPropEffects().get(
						MmochatPropType.经验冻结丹.getEffectKey());
				if (propEffect != null) {
					long useTime = System.currentTimeMillis()
							- propEffect.getStartTime();
					long restTime = propEffect.getRestAmount() - useTime;
					int restDay = (int) (restTime / MmochatConstant.MS_PER_DAY);
					if (restDay < 10) {
						String info = "您的"
								+ MmochatUtil.wrapColor("经验冻结丹", Color.yellow)
								+ "效果即将到期，还剩"
								+ MmochatUtil.wrapColor(restDay + "天",
										Color.red)
								+ "，请及时补充新的经验冻结丹，以免到期后角色经验增加。";
						MmochatFriendService.sendMsgToPersonByFriendMessage(
								role, info);
						MmochatChatService.sendSystemMsgToPerson(role, info);
					}
				}
			} catch (Exception e1) {
			}

			// 验证钱庄密码
			if (role.getStore_pwd_state() != MmochatStorePwdState.未设置钱庄密码
					&& !role.isHasCheckStorePwd()) {
				// 有密码，且未验证过，进行密码验证
				CreateEditBoxTLV edit = new CreateEditBoxTLV();
				edit.setTitle("请输入钱庄密码:");
				edit.setLeftName("确定");
				edit.setRightName("取消");
				edit.setContentLenMax(18);
				edit.setBoxType(CreateEditBoxTLV.TYPE_MSGBOX);
				edit.setInputType(CreateEditBoxTLV.INPUT_ANY << 4);
				edit.addLeftTLV(new ClearDataTLV());
				edit.addLeftTLV(new AddDataTLV((int) role.getRoleId()));
				edit.addLeftTLV(new AddEditBoxTLV());
				edit.addLeftTLV(new SendDataTLV(MmochatConstant
						.getClientModuleId(), MmochatMain.getModuleInstID(),
						MmochatConstant.MSGCODE_MMOCHAT_C_9_47, null));
				ShowWaitingMsgBoxTLV wait = new ShowWaitingMsgBoxTLV();
				wait.setShowCancel(true);
				edit.addLeftTLV(wait);

				CtrlTLVStructureRequest checkPwdTLV = new CtrlTLVStructureRequest(
						0, edit);
				checkPwdTLV.setSrcId(MmochatMain.getModuleInstID());
				checkPwdTLV.setDstId(MmochatConstant.getClientModuleId());
				checkPwdTLV.setMsgCode(MmochatConstant.MSGCODE_MMOCHAT_S_10_20);
				MmochatUtil.sendCommonPack(role, checkPwdTLV);

			}

			try {
				// 伤害、速度在线排行
				MmochatNpcService.dealOnlineRank(role);
			} catch (Exception e) {
				e.printStackTrace();
			}

			return null;
		}

	}

	// 设置公告信息
	// public static void setAnnouncement(String info) {
	// if (info == null || info.length() == 0) {
	// announcement = null;
	// } else {
	// announcement = info;
	// }
	// }
	//
	// public static String getAnnouncement() {
	// return announcement;
	// }

	// 离开游戏
	@SkymobiService
	public void handleC_LeaveGame(SkymobiHandler handler, Mmochat_LeaveGame req) {
		if (MmochatGmService.isSystemExit()) {
			// 系统正在退出，不再处理离开游戏协议
			return;
		}
		MmochatPlayer role = players.get(MmochatPlayer.getRealRoleId(req
				.getRoleId()));
		if (role == null) {
			return;
		}
		if (role.isGuest()) {
			leaveGame(role, true);
		} else {
			leaveGame(role, false);
		}
	}

	// 1.3获取角色列表
	@SkymobiService
	public SkymobiProtocolMessage handleC_1_3(SkymobiHandler handler,
			Mmochat_1_3C req) {
		if (MmochatGmService.isSystemExit()) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器正在重启，请稍候再进!");
		}
		if (players.size() >= MmochatConstant.maxRolePerServer) {
			return MmochatUtil.msgbox(req.getHallState(),
					"本区人数已爆满，请选择其它区服或稍候再试!");
		}
		if (MmochatMain.serverType == MmochatServerType.跨服战服务器) {
			Date now = new Date();
			SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
			String curTimeString = sdf.format(now);

			MmochatSimplePlayer userSimpleInfo = new MmochatSimplePlayer();
			// 如果在内存中，则允许登陆
			MmochatPlayer me = getRoleFromBufferBySkyId(req.getSkyId());
			if (me == null) {
				MmochatTempUserInfo userInfo = MmochatMultiServerPkService.tmpUsers
						.get(req.getSkyId());
				if (userInfo == null) {
					return MmochatUtil.msgbox(req.getHallState(),
							"跨服专区需要在您所在的区服内，向特定NPC申请后，再由此登陆!" + "当前跨服区时间:"
									+ curTimeString);
				}
				userSimpleInfo.setName(userInfo.getName());
				userSimpleInfo.setLevel(userInfo.getLevel());
				userSimpleInfo.setFamily(userInfo.getFamily());
			} else {
				userSimpleInfo.setName(me.getName());
				userSimpleInfo.setLevel(me.getLevel());
				userSimpleInfo.setFamily(me.getFamily());
			}

			List<MmochatSimplePlayer> roleList = new ArrayList<MmochatSimplePlayer>();
			roleList.add(userSimpleInfo);
			Mmochat_1_3S pack = new Mmochat_1_3S();
			pack.setHallState(req.getHallState());
			pack.setRoles(roleList);
			return pack;
		} else {
			List<MmochatSimplePlayer> roleList = null;
			try {
				roleList = MmochatDao.getRoleList(req.getSkyId());
			} catch (Exception e) {
				// 访问数据库失败
				e.printStackTrace();
				return MmochatUtil.msgbox(req.getHallState(), "当前服务器忙,请稍候再试!");
			}
			if (roleList == null) {
				roleList = new ArrayList<MmochatSimplePlayer>();
			}
			Mmochat_1_3S pack = new Mmochat_1_3S();
			pack.setHallState(req.getHallState());
			pack.setRoles(roleList);
			return pack;
		}
	}

	// 检查角色名是否合法
	public static boolean isRoleNameValid(String name) {
		String upperName = name.toUpperCase();
		if ((upperName.contains("G") && upperName.contains("M"))
				|| (upperName.contains("客") && upperName.contains("服"))
				|| (upperName.contains("工") && upperName.contains("作"))
				|| (upperName.contains("克") && upperName.contains("服"))
				|| (upperName.contains("服") && upperName.contains("务"))
				|| (upperName.contains("服") && upperName.contains("器"))
				|| upperName.contains("小强")
				|| (upperName.contains("系") && upperName.contains("统"))
				|| upperName.contains("奖") || upperName.contains("恭喜")
				|| upperName.contains("推荐") || upperName.contains("斯凯")
				|| upperName.contains("") || upperName.contains("")
				|| upperName.contains("") || upperName.contains("")
				|| upperName.contains("") || upperName.contains("_")
				|| upperName.contains("\n") || upperName.contains("\r")) {
			return false;
		}
		return !MmochatFilterService.isHasFilterWord(upperName);
	}

	// 1.4创建新角色
	@SkymobiService
	public SkymobiProtocolMessage handleC_1_4(SkymobiHandler handler,
			Mmochat_1_4C req) {
		if (MmochatGmService.isSystemExit()) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器正在重启，请稍候再试!");
		}
		if (MmochatMain.serverType == MmochatServerType.跨服战服务器) {
			return MmochatUtil.msgbox(req.getHallState(), "跨服区内无法进行此操作!");
		}
		String name = req.getName();
		if (name.length() > MmochatConstant.maxNameLen || name.length() <= 0) {
			return MmochatUtil.msgbox(req.getHallState(), "昵称最短1个字,最长"
					+ MmochatConstant.maxNameLen + "个字!");
		}
		String patternStr = ".*\\s.*";
		boolean result = Pattern.matches(patternStr, name);
		if (result) {
			return MmochatUtil.msgbox(req.getHallState(), "昵称中不能包含空格,请重新输入!");
		}
		if (!isRoleNameValid(name)) {
			return MmochatUtil.msgbox(req.getHallState(),
					"昵称中包含了不允许使用的字词符号，请重新输入!");
		}
		if (req.getSexual() != 0 && req.getSexual() != 1) {
			return MmochatUtil.msgbox(req.getHallState(), "性别错误!");
		}
		if (req.getParty() != 0 && req.getParty() != 1 && req.getParty() != 2) {
			return MmochatUtil.msgbox(req.getHallState(), "门派错误!");
		}
		String imei = req.getImei();
		String suggestName = "";
		int suggestRoleId = -1;
		if (req.getSuggestName() != null) {
			suggestName = req.getSuggestName().trim();
		}
		do {
			if (suggestName != null && suggestName.length() > 0) {
				// 填写了推荐人，检查推荐人是否存在
				boolean ret = false;
				int zoneId = -1;
				String suggestRoleName = null;
				do {
					int index = suggestName.indexOf("区");
					if (index == -1) {
						break;
					}
					String zoneStr = suggestName.substring(0, index);
					suggestRoleName = suggestName.substring(index + 1);
					try {
						zoneId = Integer.parseInt(zoneStr);
						if (suggestRoleName == null
								|| suggestRoleName.length() == 0) {
							break;
						}
					} catch (NumberFormatException e) {
						break;
					}
					ret = true;
				} while (false);
				if (!ret) {
					return MmochatUtil.msgbox(req.getHallState(),
							"推荐人填写错误!推荐人的格式是：几区玩家名，如：1区小强。(推荐人可以不填写)");
				}
				Integer dstModuleId = MmochatMain
						.getInstanceIdByServerId(zoneId);
				if (dstModuleId == null) {
					// 区服不存在或尚未获取到区服信息
					return MmochatUtil.msgbox(req.getHallState(),
							"您填写的推荐人不存在，请重新填写!(推荐人可以不填写)");
				}
				// 向此区服请求验证推荐人是否合法：存在，且与此玩家不是同一人
				if (dstModuleId == MmochatMain.getModuleInstID()) {
					// 推荐人与此玩家是同一区服，进行同服验证
					// 验证结果 0:成功；1:属同一玩家；2:不存在；3:超时或异常
					// 先从在线玩家中查找
					MmochatPlayer suggester = MmochatGmService
							.getRoleInfoByName(suggestRoleName);
					if (suggester == null) {
						return MmochatUtil.msgbox(req.getHallState(),
								"您填写的推荐人不存在，请重新填写!(推荐人可以不填写)");
					} else if (suggester.getSkyId() == req.getSkyId()
							|| (suggester.getImei() != null
									&& suggester.getImei().length() > 0
									&& req.getImei() != null
									&& req.getImei().length() > 0 && suggester
									.getImei().equals(req.getImei()))) {
						return MmochatUtil.msgbox(req.getHallState(),
								"不能填写自己的相关账号为推荐人。");
					} else {
						// 填写的推荐人合法
						log.debug("填写的本区服推荐人合法");
						suggestName = zoneId + "区" + suggester.getRoleId();
						suggestRoleId = suggester.getRoleId();
						break;
					}
				} else {
					// 推荐人与玩家不在同一区服，进行跨服验证
					// 先将注册信息缓存起来
					MmochatRegisterInfo regInfo = new MmochatRegisterInfo();
					regInfo.setSexual(req.getSexual());
					regInfo.setParty(req.getParty());
					regInfo.setName(req.getName());
					regInfo.setSuggestName(req.getSuggestName());
					regInfo.setImei(req.getImei());
					regInfo.setConn(req.getUserConnInfo());
					regInfo.setHallState(req.getHallState());
					registerBuffer.put(req.getSkyId(), regInfo);

					Mmochat_CheckSuggesterInfo pack = new Mmochat_CheckSuggesterInfo();
					pack.setSrcModuleId(MmochatMain.getModuleInstID());
					pack.setDstModuleId(dstModuleId);
					pack.setImei(imei);
					pack.setSkyId(req.getSkyId());
					pack.setSuggestName(suggestRoleName);
					String zoneName = "";
					if (MmochatMain.getServerName() != null) {
						zoneName = "(" + MmochatMain.getServerName() + "区)";
					}
					String info = MmochatUtil.wrapColor(name, Color.green)
							+ zoneName + "已经将您填写为推荐人!";
					pack.setInfo(info);

					checkSuggestInfoCb cb = new checkSuggestInfoCb();
					cb.setConn(req.getUserConnInfo());
					cb.setSkyId(req.getSkyId());
					SkymobiHandler handle = MmochatMainService
							.getCommonHandler();
					if (handle != null) {
						handle.asyncPushSkymobiModuleMessage(pack, cb, 5000,
								TimeUnit.MILLISECONDS);
					}
					return null;
				}
			}
		} while (false);
		// 没填写推荐人或推荐人验证OK
		int roleTypeValue = 0;
		int friendListBmp = 0;
		if (req.getSexual() == 0 && req.getParty() == 0) {
			roleTypeValue = MmochatRoleType.阐教男.getValue();
			friendListBmp = MmochatConstant.BMP_BOYTAG;
		} else if (req.getSexual() == 1 && req.getParty() == 0) {
			roleTypeValue = MmochatRoleType.阐教女.getValue();
			friendListBmp = MmochatConstant.BMP_GIRLTAG;
		} else if (req.getSexual() == 0 && req.getParty() == 1) {
			roleTypeValue = MmochatRoleType.人教男.getValue();
			friendListBmp = MmochatConstant.BMP_BOYTAG;
		} else if (req.getSexual() == 1 && req.getParty() == 1) {
			roleTypeValue = MmochatRoleType.人教女.getValue();
			friendListBmp = MmochatConstant.BMP_GIRLTAG;
		} else if (req.getSexual() == 0 && req.getParty() == 2) {
			roleTypeValue = MmochatRoleType.截教男.getValue();
			friendListBmp = MmochatConstant.BMP_BOYTAG;
		} else if (req.getSexual() == 1 && req.getParty() == 2) {
			roleTypeValue = MmochatRoleType.截教女.getValue();
			friendListBmp = MmochatConstant.BMP_GIRLTAG;
		}
		try {
			MmochatDao.createRole(req.getSkyId(), name, req.getSexual(), req
					.getParty(), roleTypeValue, friendListBmp, suggestName, req
					.getImei());
		} catch (DataIntegrityViolationException e) {
			return MmochatUtil.msgbox(req.getHallState(), "该角色名已存在!");
		} catch (Exception e) {
			e.printStackTrace();
			return MmochatUtil.msgbox(req.getHallState(), "当前服务器忙,请稍候再试!");
		}

		// 创建成功,返回角色列表
		MmochatStatisticsService.todayRegisterNum++;
		if (suggestName != null && suggestName.length() > 0) {
			MmochatStatisticsService.todayRegisterWithSuggesterNum++;
			// 向推荐人发送通知消息
			String info = MmochatUtil.wrapColor(name, Color.green)
					+ "(本区服)已经将您填写为推荐人!";
			MmochatGmService.sendKufuPrivateMsg(suggestRoleId, info, false);
		}
		List<MmochatSimplePlayer> roleList;
		try {
			roleList = MmochatDao.getRoleList(req.getSkyId());
		} catch (Exception e) {
			// 访问数据库失败
			e.printStackTrace();
			return MmochatUtil.msgbox(req.getHallState(), "当前服务器忙,请稍候再试!");
		}
		if (roleList == null) {
			roleList = new ArrayList<MmochatSimplePlayer>();
		}
		Mmochat_1_3S pack = new Mmochat_1_3S();
		pack.setHallState(req.getHallState());
		pack.setRoles(roleList);

		return pack;
	}

	// 验证推荐人的返回消息处理
	private class checkSuggestInfoCb extends
			AsyncRunnable<Mmochat_CheckSuggesterInfo> {
		private UserConnInfo conn = null;
		private long skyId;

		public void setConn(UserConnInfo conn) {
			this.conn = conn;
		}

		public void setSkyId(long skyId) {
			this.skyId = skyId;
		}

		@Override
		public void run() {
			try {
				getResult();
				// 没报异常表示消息已经成功发出，但不代表已经收到回复，这里不作处理
			} catch (SkymobiException e) {
				MmochatUtil.sendCommonMsgbox(conn, "验证推荐人异常!请稍候再试，或不填写推荐人。");
				registerBuffer.remove(skyId);
			} catch (TimeoutException e) {
				MmochatUtil.sendCommonMsgbox(conn, "验证推荐人超时!请稍候再试，或不填写推荐人。");
				registerBuffer.remove(skyId);
			}
		}
	}

	// 验证推荐人
	@SkymobiService
	public SkymobiModuleMessage handleCheckSuggestInfoMessage(
			SkymobiHandler handler, Mmochat_CheckSuggesterInfo req) {
		// 验证结果 0:成功；1:属同一玩家；2:不存在；3:超时或异常
		int ret;
		int suggestRoleId = -1;
		MmochatPlayer suggester = MmochatGmService.getRoleInfoByName(req
				.getSuggestName());
		if (suggester == null) {
			ret = 2;
			log.debug("填写的推荐人不存在");
		} else if (suggester.getSkyId() == req.getSkyId()
				|| (suggester.getImei() != null
						&& suggester.getImei().length() > 0
						&& req.getImei() != null && req.getImei().length() > 0 && suggester
						.getImei().equals(req.getImei()))) {
			ret = 1;
			log.debug("填写的推荐人与玩家是同一个人");
		} else {
			ret = 0;
			suggestRoleId = suggester.getRoleId();
			log.debug("填写的推荐人合法");

			// 向推荐人发送通知消息
			MmochatGmService.sendKufuPrivateMsg(suggestRoleId, req.getInfo(),
					false);
		}

		Mmochat_CheckSuggesterInfoRet pack = new Mmochat_CheckSuggesterInfoRet();
		pack.setRet(ret);
		pack.setSuggestRoleId(suggestRoleId);
		pack.setSkyId(req.getSkyId());
		return pack;
	}

	// 收到验证推荐人回复
	@SkymobiService
	public void handleCheckSuggestInfoRetMessage(SkymobiHandler handler,
			Mmochat_CheckSuggesterInfoRet req) {
		MmochatRegisterInfo regInfo = registerBuffer.remove(req.getSkyId());
		if (regInfo == null) {
			return;
		}
		switch (req.getRet()) {
		case 0:
			// 验证推荐人成功，创建角色
			String newSuggestName = "";
			String suggestName = regInfo.getSuggestName();
			int zoneId = -1;
			String suggestRoleName = null;
			do {
				int index = suggestName.indexOf("区");
				if (index == -1) {
					break;
				}
				String zoneStr = suggestName.substring(0, index);
				suggestRoleName = suggestName.substring(index + 1);
				try {
					zoneId = Integer.parseInt(zoneStr);
					if (suggestRoleName == null
							|| suggestRoleName.length() == 0) {
						break;
					}
				} catch (NumberFormatException e) {
					break;
				}
				newSuggestName = zoneId + "区" + req.getSuggestRoleId();
			} while (false);

			int roleTypeValue = 0;
			int friendListBmp = 0;
			if (regInfo.getSexual() == 0 && regInfo.getParty() == 0) {
				roleTypeValue = MmochatRoleType.阐教男.getValue();
				friendListBmp = MmochatConstant.BMP_BOYTAG;
			} else if (regInfo.getSexual() == 1 && regInfo.getParty() == 0) {
				roleTypeValue = MmochatRoleType.阐教女.getValue();
				friendListBmp = MmochatConstant.BMP_GIRLTAG;
			} else if (regInfo.getSexual() == 0 && regInfo.getParty() == 1) {
				roleTypeValue = MmochatRoleType.人教男.getValue();
				friendListBmp = MmochatConstant.BMP_BOYTAG;
			} else if (regInfo.getSexual() == 1 && regInfo.getParty() == 1) {
				roleTypeValue = MmochatRoleType.人教女.getValue();
				friendListBmp = MmochatConstant.BMP_GIRLTAG;
			} else if (regInfo.getSexual() == 0 && regInfo.getParty() == 2) {
				roleTypeValue = MmochatRoleType.截教男.getValue();
				friendListBmp = MmochatConstant.BMP_BOYTAG;
			} else if (regInfo.getSexual() == 1 && regInfo.getParty() == 2) {
				roleTypeValue = MmochatRoleType.截教女.getValue();
				friendListBmp = MmochatConstant.BMP_GIRLTAG;
			}
			try {
				MmochatDao.createRole(req.getSkyId(), regInfo.getName(),
						regInfo.getSexual(), regInfo.getParty(), roleTypeValue,
						friendListBmp, newSuggestName, regInfo.getImei());
			} catch (DataIntegrityViolationException e) {
				MmochatUtil.sendCommonMsgbox(regInfo.getConn(), "该角色名已存在!");
				return;
			} catch (Exception e) {
				e.printStackTrace();
				MmochatUtil
						.sendCommonMsgbox(regInfo.getConn(), "当前服务器忙,请稍候再试!");
				return;
			}

			// 创建成功,返回角色列表
			MmochatStatisticsService.todayRegisterNum++;
			MmochatStatisticsService.todayRegisterWithSuggesterNum++;
			List<MmochatSimplePlayer> roleList;
			try {
				roleList = MmochatDao.getRoleList(req.getSkyId());
			} catch (Exception e) {
				// 访问数据库失败
				e.printStackTrace();
				MmochatUtil
						.sendCommonMsgbox(regInfo.getConn(), "当前服务器忙,请稍候再试!");
				return;
			}
			if (roleList == null) {
				roleList = new ArrayList<MmochatSimplePlayer>();
			}
			// 下发角色列表
			Mmochat_1_3S pack = new Mmochat_1_3S();
			pack.setHallState(regInfo.getHallState());
			pack.setRoles(roleList);
			pack.setSrcId(MmochatMain.getModuleInstID());
			pack.setDstId(MmochatConstant.getClientModuleId());
			pack.setUserConnInfo(regInfo.getConn());
			SkymobiHandler handle = MmochatMainService.getCommonHandler();
			if (handle != null) {
				try {
					handle.pushSkymobiMessage(pack);
				} catch (NoConnectionException e) {
					e.printStackTrace();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			break;
		case 1:
			// 推荐人与玩家是同一人
			MmochatUtil.sendCommonMsgbox(regInfo.getConn(), "不能填写自己的相关账号为推荐人。");
			break;
		case 2:
			// 不存在的推荐人
			MmochatUtil.sendCommonMsgbox(regInfo.getConn(),
					"您填写的推荐人不存在!推荐人的格式是：" + "几区玩家名，如：1区小强。(推荐人可以不填写)");
			break;
		case 3:
			// 超时或异常
			MmochatUtil.sendCommonMsgbox(regInfo.getConn(),
					"验证推荐人超时!请稍候再试，或不填写推荐人。");
			break;
		default:
			break;
		}
	}

	// 发放推荐人奖励
	@SkymobiService
	public void handleSendSuggestAwardMessage(SkymobiHandler handler,
			Mmochat_SendSuggestAward req) {
		int awardCount = req.getAwardCount();
		int suggestRoleId = req.getSuggestRoleId();
		String content = req.getAwardMsg();
		// 先在数据库中增加积分
		int row = 0;
		try {
			row = MmochatDao.addSuggestScore(awardCount, suggestRoleId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (row > 0) {
			MmochatPlayer suggester = MmochatMainService
					.getRoleFromBuffer(suggestRoleId);
			if (suggester != null) {
				// 在线
				suggester.addSuggestScore(awardCount);
			}
			// 下发客服消息
			if (content != null) {
				MmochatGmService.sendKufuPrivateMsg(suggestRoleId, content,
						false);
			}
		}
	}

	// 1.15换线
	@SkymobiService
	public SkymobiProtocolMessage handleC_1_15(SkymobiHandler handler,
			Mmochat_1_15C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		if (me.isInBattle()) {
			log.debug("玩家" + me.getName() + "(skyid=" + me.getSkyId()
					+ ")已进入战斗,无法换线");
			return null;
		}
		// if (MmochatMain.serverType == MmochatServerType.跨服战服务器) {
		// return MmochatUtil.msgbox(req.getHallState(), "跨服区内无法进行此操作!");
		// }
		if (MmochatTeamService.getTeamState(me) == MmochatTeamStateType.队员) {
			return MmochatUtil.msgbox(req.getHallState(), "组队状态下只有队长才能换线!");
		}

		if (me.getLine() == req.getLine()) {
			// 已经在此线
			CreateMsgBoxTLV msgbox = new CreateMsgBoxTLV();
			msgbox.setContent(new Text("您已经在" + req.getLine() + "线了!"));
			msgbox.setLeftName("确定");
			return MmochatUtil.tlvResponse(req.getHallState(), new CloseWinTLV(
					MmochatConstant.TLV_WIN_LINELIST), msgbox);
		}

		int lineNum = 0;
		int line = req.getLine();
		for (MmochatMap map : MmochatMapService.maps.values()) {
			if (map != null) {
				lineNum += map.getLineRoleMap(line).size();
			}
		}
		if (lineNum >= MmochatConstant.maxRoleNumPerMapLine) {
			return MmochatUtil.msgbox(req.getHallState(), "本线人数已满,请选择其它线路!");
		}

		if (lineNum >= MmochatConstant.maxNormalRoleNumPerLine) {
			if (!me.hasPropEffect(MmochatPropType.会员周卡.getEffectKey())) {
				return MmochatUtil.msgbox(req.getHallState(),
						"本线人数拥挤,请选择其它线路!会员可以不受限制进入拥挤线路。");
			}
		}

		// 组队换线操作
		{
			List<MmochatPlayer> members = new ArrayList<MmochatPlayer>();
			if (me.isInTeam()) {
				MmochatTeam team = MmochatTeamService.teams.get(me.getTeamId());
				if (team == null) {
					me.leaveTeam();
					members.add(me);
				} else {
					for (Integer roleId : team.getMemberId().values()) {
						MmochatPlayer member = MmochatMainService.players
								.get(roleId);
						if (member != null) {
							members.add(member);
						} else {
							team.delMember(roleId);
						}
					}
				}
			} else {
				members.add(me);
			}
			if (members.size() <= 0) {
				log.debug("玩家" + me.getName() + "(skyid=" + me.getSkyId()
						+ ")传送人数为0，无法换线;");
				return null;
			}
			for (MmochatPlayer member : members) {
				if (!member.lockState(MmochatRoleStateType.换线时)) {
					log.debug(member.getName() + "当前状态为:"
							+ member.getState().toString() + "，无法换线");
					continue;
				}

				// 开始换线

				// TODO:其它处理
				// 停止交易
				member.stopDeal();

				// 清除周围玩家
				member.getSceenRoles().clear();

				// 清除坐标缓存器
				member.getPositionBuffer().clear();

				// 清除NPC列表
				member.getTmpNpcs().clear();

				// 从旧的线中移除
				MmochatMap curMap = MmochatMapService.getMapByMapId(member
						.getMapId());
				if (curMap == null) {
					// 地图不存在,可能之前所在临时地图已经关闭,将其转移到固定地图
					MmochatMapTransPoint newPos = MmochatMap
							.getMapWhenTempMapNotFound(member.getMapId());
					curMap = MmochatMapService.getMapByMapId(newPos
							.getTransToMapId());
					member.setX(newPos.getNewMapX());
					member.setY(newPos.getNewMapY());
					member.setMapId(newPos.getTransToMapId());
				}
				curMap.delRole(member.getLine(), member);

				// 设置新线
				member.setLine(req.getLine());

				Mmochat_1_1S pack = new Mmochat_1_1S();
				// 不使用hallState进行判断,以免终端连续上传两次请求后,终端hallState被第二次请求发送时更改
				pack.setMap(curMap);
				pack.setLine((int) req.getLine());
				pack.setMe(member);
				enterGame(member, member.getUserConnInfo(), pack);
				MmochatUtil.sendCommonPack(member, pack);
				try {
					MmochatDao.updateRoleChangeLine(member, req.getLine());
				} catch (Exception e) {
					e.printStackTrace();
				}

				member.unLockState();
				log.debug("玩家" + member.getName() + "(skyid="
						+ member.getSkyId() + ")完成换线");
			}
		}
		return null;
	}

	// 删除角色
	@SkymobiService
	public SkymobiProtocolMessage handleC_1_13(SkymobiHandler handler,
			Mmochat_1_13C req) {
		if (MmochatMain.serverType == MmochatServerType.跨服战服务器) {
			return MmochatUtil.msgbox(req.getHallState(), "跨服区内无法进行此操作!");
		}
		CreateMsgBoxTLV msgbox = new CreateMsgBoxTLV();
		msgbox.setContent(new Text("删除角色后无法恢复,你确定要删除此角色么?"));
		msgbox.setLeftName("删除");
		msgbox.setRightName("取消");
		msgbox.addLeftTLV(new ClearDataTLV());
		msgbox.addLeftTLV(new SendDataTLV(MmochatConstant.getClientModuleId(),
				MmochatMain.getModuleInstID(),
				MmochatConstant.MSGCODE_MMOCHAT_C_1_14, (int) req.getRoleId()));
		ShowWaitingMsgBoxTLV wait = new ShowWaitingMsgBoxTLV();
		wait.setShowCancel(false);
		msgbox.addLeftTLV(wait);

		return MmochatUtil.tlvResponse(req.getHallState(), msgbox);
	}

	// 删除角色操作
	@SkymobiService
	public SkymobiProtocolMessage handleC_1_14(SkymobiHandler handler,
			Mmochat_1_14C req) {
		if (MmochatMain.serverType == MmochatServerType.跨服战服务器) {
			return MmochatUtil.msgbox(req.getHallState(), "跨服区内无法进行此操作!");
		}
		try {
			MmochatPlayer he = MmochatDao.getRole(req.getRoleId());
			if (he == null) {
				return null;
			}
			he.setUserConnInfo(req.getUserConnInfo());
			if (he.getStore_pwd_state() != MmochatStorePwdState.未设置钱庄密码) {
				return MmochatUtil.msgbox(req.getHallState(), MmochatUtil
						.wrapColor("您设置了钱庄密码，请先到钱庄解除密码!", Color.red));
			}
			long today = (new Date()).getTime();
			if (he.getBig_money() > 100) {
				return MmochatUtil.msgbox(req.getHallState(), MmochatUtil
						.wrapColor("您此角色中的元宝尚未用完，无法删除角色。", Color.red));
			}
			if (he.getLevel() >= 100
					&& today - he.getLatest_login_time() < 7 * MmochatConstant.MS_PER_DAY) {
				return MmochatUtil.msgbox(req.getHallState(), MmochatUtil
						.wrapColor("为防止被他人恶意删号，100级以上角色要求连续七天不登陆游戏", Color.red)
						+ ",才可以申请删除角色。此角色七天内曾经登陆过游戏!");
			} else if (he.getLevel() >= 50
					&& today - he.getLatest_login_time() < 2 * MmochatConstant.MS_PER_DAY) {
				return MmochatUtil.msgbox(req.getHallState(), MmochatUtil
						.wrapColor("为防止被他人恶意删号，50级以上角色要求连续两天不登陆游戏", Color.red)
						+ ",才可以申请删除角色。此角色两天内曾经登陆过游戏!");
			}
		} catch (Exception e1) {
			e1.printStackTrace();
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}

		try {
			MmochatDao.delRole(req.getRoleId(), true);
		} catch (Exception e) {
			e.printStackTrace();
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}

		List<MmochatSimplePlayer> roleList = null;
		try {
			roleList = MmochatDao.getRoleList(req.getSkyId());
		} catch (Exception e) {
			// 访问数据库失败
			e.printStackTrace();
			return MmochatUtil.msgbox(req.getHallState(),
					"角色已删除,请重新进入,以获取新的角色列表!");
		}
		if (roleList == null) {
			roleList = new ArrayList<MmochatSimplePlayer>();
		}
		Mmochat_1_3S pack = new Mmochat_1_3S();
		pack.setHallState(req.getHallState());
		pack.setRoles(roleList);
		return pack;
	}

	// 1.8 终端通知地图传送
	@SkymobiService
	public SkymobiProtocolMessage handleC_1_8(SkymobiHandler handler,
			Mmochat_1_8C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return null;
		}
		if (me.isLockTrans()) {
			log.debug("玩家" + me.getName() + "已被锁定传送，忽略本次切换地图消息");
			return null;
		}
		if (me.getMapId() != (int) req.getMapId()
				|| me.getLine() != (int) req.getLine()) {
			log.debug("玩家" + me.getName() + "(skyid=" + me.getSkyId()
					+ ")终端位置与服务端不一致，无法传送;服务端mapId=" + me.getMapId() + ",line="
					+ me.getLine() + ",终端mapId=" + req.getMapId() + ",line="
					+ req.getLine());
			return null;
		}

		// 除我之外的其它队员
		List<MmochatPlayer> members = new ArrayList<MmochatPlayer>();
		if (me.isInTeam()) {
			MmochatTeam team = MmochatTeamService.teams.get(me.getTeamId());
			if (team == null) {
				me.leaveTeam();
			} else {
				if (!team.isTeamLeader(me.getRoleId())) {
					log.debug("玩家" + me.getName() + "(skyid=" + me.getSkyId()
							+ ")在队伍中，且不为队长，无法传送;");
					return null;
				}
				for (Integer roleId : team.getMemberId().values()) {
					if (roleId != me.getRoleId()) {
						MmochatPlayer member = MmochatMainService.players
								.get(roleId);
						if (member != null) {
							members.add(member);
						}
					}
				}
			}
		}

		// 通过x,y决定传送到哪个地图哪个传送口附近
		MmochatMap curMap = MmochatMapService.getMapByMapId(me.getMapId());
		MmochatMapTransPoint trans = curMap.getTransPoint((int) req.getX(),
				(int) req.getY());
		if (trans == null) {
			log.debug("未知传送目的地!");
			return null;
		}
		MmochatMap newMap = MmochatMapService.getMapByMapId(trans
				.getTransToMapId());
		if (newMap == null) {
			log.debug("未知传送目的地!");
			return null;
		}

		// 更新我的地图数据
		// 清除周围玩家
		me.getSceenRoles().clear();

		// 清除坐标缓存器
		me.getPositionBuffer().clear();

		// 清除NPC列表
		me.getTmpNpcs().clear();

		// 从旧的地图中移除
		if (curMap != null) {
			curMap.delRole(req.getLine(), me);
		}

		String hint = null;
		if (!curMap.isWalkToBattle() && newMap.isWalkToBattle()) {
			hint = "您已进入" + MmochatUtil.wrapColor("非安全区", Color.red)
					+ "，在这里与他人切磋属于强制杀戮，战斗失败会死亡!";
		}
		if (curMap.isWalkToBattle() && !newMap.isWalkToBattle()) {
			hint = "您已进入" + MmochatUtil.wrapColor("安全区", Color.green)
					+ "，在这里与他人切磋，战斗失败不会有任何损失!";
		}

		// 设置新坐标
		me.setX(trans.getNewMapX());
		me.setY(trans.getNewMapY());
		me.setMapId(newMap.getMapId());

		newMap.addRole(req.getLine(), me);
		Mmochat_1_21S pack = new Mmochat_1_21S();
		pack.setMe(me);
		pack.setLine(req.getLine());
		pack.setMap(newMap);

		// 将其它玩家加入我的视界
		for (MmochatPlayer other : newMap.getLineRoleMap(req.getLine())
				.values()) {
			try {
				if (me.getSceenRoles().size() >= me.getMax_screen_role_num()) {
					break;
				}
				if (other.getRoleId() != me.getRoleId()) {
					if (Math.abs(other.getX() - me.getX()) < MmochatConstant.screenWidth
							&& Math.abs(other.getY() - me.getY()) < MmochatConstant.screenHeight) {
						// 视界范围内
						if (me.getMyEnermys().get(other.getRoleId()) != null) {
							// 在我的黑名单中
							continue;
						} else if (me.getShowRoleSet() == MmochatShowRoleSet.隐藏所有人) {
							continue;
						} else if (me.getShowRoleSet() == MmochatShowRoleSet.只显示队长) {
							if (MmochatTeamService.getTeamState(other) == MmochatTeamStateType.队长) {
								pack.addSceenRole(other);
								me.addSceenRole(other.getRoleId(), other
										.getStateValue(me));
							}
						} else if (me.getShowRoleSet() == MmochatShowRoleSet.只显示好友) {
							if (me.getMyDearFriends().get(other.getRoleId()) != null) {
								pack.addSceenRole(other);
								me.addSceenRole(other.getRoleId(), other
										.getStateValue(me));
							}
						} else if (me.getShowRoleSet() == MmochatShowRoleSet.显示所有人) {
							pack.addSceenRole(other);
							me.addSceenRole(other.getRoleId(), other
									.getStateValue(me));
						}
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		MmochatUtil.sendCommonPack(me, pack);
		if (hint != null) {
			MmochatChatService.sendSystemMsgToPerson(me, hint);
		}

		// 将本队其它人马传到新地图新坐标
		if (members.size() > 0) {
			MmochatMapService
					.tranToNewMap(curMap, me.getLine(), newMap, req.getLine(),
							trans.getNewMapX(), trans.getNewMapY(), members);
			if (hint != null) {
				for (MmochatPlayer he : members) {
					MmochatChatService.sendSystemMsgToPerson(he, hint);
				}
			}
		}

		log.debug("玩家" + me.getName() + "(skyid=" + me.getSkyId() + ")完成传送");
		return null;
	}

	// 1.9飞回师门
	@SkymobiService
	public SkymobiProtocolMessage handleC_1_9(SkymobiHandler handler,
			Mmochat_1_9C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		if (MmochatMain.serverType == MmochatServerType.跨服战服务器) {
			return MmochatUtil.msgbox(req.getHallState(), "跨服区内无法使用此功能!");
		}
		if (me.isInBattle()) {
			log.debug("玩家" + me.getName() + "(skyid=" + me.getSkyId()
					+ ")已进入战斗,无法传送");
			return null;
		}
		if (me.isInTeam()) {
			return MmochatUtil.msgbox(req.getHallState(), "组队状态下无法飞回门派!");
		}

		if (me.hasYBTask()) {
			return MmochatUtil.msgbox(req.getHallState(),
					"押送镖银过程中无法飞回门派!您需要先放弃或完成此任务，才能飞回门派!");
		}

		int targetMapId;
		int targetPosX, targetPosY;
		// TODO:传送目标坐标与门派传送员坐标相近
		switch (me.getFamily()) {
		case 阐教:
			targetMapId = MmochatConstant.mapId_阐教;
			targetPosX = 308;
			targetPosY = 310;
			break;
		case 人教:
			targetMapId = MmochatConstant.mapId_人教;
			targetPosX = 320;
			targetPosY = 210;
			break;
		case 截教:
			targetMapId = MmochatConstant.mapId_截教;
			targetPosX = 270;
			targetPosY = 220;
			break;
		default:
			log.debug("玩家" + me.getName() + "(skyid=" + me.getSkyId()
					+ ")无门派,无法传送");
			return null;
		}
		MmochatMap curMap = MmochatMapService.getMapByMapId(me.getMapId());
		MmochatMap newMap = MmochatMapService.getMapByMapId(targetMapId);
		if (newMap == null) {
			return MmochatUtil.msgbox(req.getHallState(), "此地图暂未开放!无法前往!");
		}

		if (!me.lockState(MmochatRoleStateType.飞回师门时)) {
			return null;
		}

		// TODO:其它处理
		// 停止交易
		me.stopDeal();

		// 清除周围玩家
		me.getSceenRoles().clear();

		// 清除坐标缓存器
		me.getPositionBuffer().clear();

		// 清除NPC列表
		me.getTmpNpcs().clear();

		// 从旧的地图中移除
		if (curMap != null && newMap.getMapId() != curMap.getMapId()) {
			curMap.delRole(me.getLine(), me);
		}

		// 设置新坐标
		me.setX(targetPosX);
		me.setY(targetPosY);

		if (me.isInBattle()) {
			log.debug("玩家" + me.getName() + "(skyid=" + me.getSkyId()
					+ ")已进入战斗,无法传送");
			return null;
		}
		if (me.isInTeam()) {
			return MmochatUtil.msgbox(req.getHallState(), "组队状态下无法飞回门派!");
		}
		me.setMapId(targetMapId);
		me.unLockState();

		Mmochat_1_1S pack = new Mmochat_1_1S();
		// 不使用hallState进行判断,以免终端连续上传两次请求后,终端hallState被第二次请求发送时更改
		pack.setMap(newMap);
		pack.setLine((int) me.getLine());
		pack.setMe(me);
		enterGame(me, me.getUserConnInfo(), pack);
		synchronized (me) {
			// 坐标可能被其它线程修改，用同步保护
			me.setX(targetPosX);
			me.setY(targetPosY);
			MmochatUtil.sendCommonPack(me, pack);
		}
		if (curMap != null && curMap.getMapId() != newMap.getMapId()) {
			try {
				MmochatDao.updateRoleEnterNewMap(me);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		log.debug("玩家" + me.getName() + "(skyid=" + me.getSkyId() + ")返回师门");
		return null;
	}

	// 死亡处理
	@SuppressWarnings("deprecation")
	public static void dealDead(MmochatPlayer me) {
		if (!me.isDeadInBattle()) {
			return;
		}
		if (!me.lockState(MmochatRoleStateType.死亡回城时)) {
			return;
		}

		if (!me.isDeadInBattle()) {
			me.unLockState();
			return;
		}
		me.setDeadInBattle(false);

		boolean noHarm = false;
		String noHarmReason = "";
		MmochatDailyActivity activity = me.getDailyActivities().get(
				MmochatDailyActivityType.死亡惩罚次数);
		if (activity == null) {
			activity = new MmochatDailyActivity();
			activity.setType(MmochatDailyActivityType.死亡惩罚次数);
			me.addDailyActivity(activity);
		}
		Date now = new Date();
		Date lastDate = new Date(activity.getLastTime());
		if (now.getDate() == lastDate.getDate()
				&& now.getMonth() == lastDate.getMonth()
				&& now.getYear() == lastDate.getYear()) {
			// 今天已经死亡过了
			if (activity.getDailyTimes() >= activity.getType()
					.getMaxDailyTimes()) {
				// 死亡次数已达上限，免死
				noHarm = true;
				noHarmReason = "您今天已经战死"
						+ activity.getType().getMaxDailyTimes()
						+ "次以上，系统免除您本次死亡损失!";
			} else {
				activity.addDailyTimes(1);
			}
		} else {
			// 今天第一次死亡
			activity.setLastTime(now.getTime());
			activity.setDailyTimes(1);
		}

		// 免死道具, unlock
		boolean needBack = true;
		if (!noHarm) {
			MmochatPropEffect propEffect = me.getPropEffects().get(
					MmochatPropType.赎罪牌.getEffectKey());
			if (propEffect != null && propEffect.getRestAmount() > 0) {
				propEffect.addAmount(-1);
				if (propEffect.getRestAmount() <= 0) {
					me.delPropEffect(MmochatPropType.赎罪牌.getEffectKey());
				}
				noHarm = true;
				noHarmReason = "您消耗了一次赎罪牌,免去了死亡惩罚。";
				needBack = false;
			}
		}

		// 离开队伍
		{
			if (me.isInTeam()) {
				MmochatTeam team = MmochatTeamService.teams.get(me.getTeamId());
				if (team == null) {
					me.leaveTeam();
				} else {
					team.leaveTeam(me.getRoleId());
				}
			}
		}

		// 恢复满血
		me.setCurBlood(me.getTotalBlood());
		me.setCurSprit(me.getTotalSprit());

		for (MmochatPet pet : me.getPets().values()) {
			pet.setCurBlood(pet.getTotalBlood());
			pet.setCurSprit(pet.getTotalSprit());
		}

		// 30级以下免除死亡惩罚
		String msg = "您死亡了!";
		int delExp = 0, delDao = 0;
		if (noHarm) {
			msg += noHarmReason;
		} else if (me.getLevel() < 30) {
			msg += "由于您未到30级,所以免去死亡惩罚。";
		} else if (me.getLevel() >= 30) {
			// 扣除2%的升级经验
			int exp = MmochatBattleService.getHumanExpNeedToUplevel(me
					.getLevel(), me.getLife_turn());
			int del = (int) (exp * 0.02);
			del = Math.max(0, del);
			del = Math.min(del, 100000);
			delExp = me.getExp();
			me.addExp(-1 * del);
			delExp = delExp - me.getExp();

			// 扣除道行
			int dao = 365;
			delDao = me.getDao();
			me.addDao(-1 * dao);
			delDao = delDao - me.getDao();

			msg += "您损失了" + delExp + "点经验和" + delDao + "天道行。";
		}

		if (needBack) {

			// 转移到出生地
			MmochatMap curMap = MmochatMapService.getMapByMapId(me.getMapId());
			MmochatMap newMap = MmochatMapService
					.getMapByMapId(MmochatConstant.mapId_西岐);

			// TODO:其它处理
			// 停止交易
			me.stopDeal();

			// 清除周围玩家
			me.getSceenRoles().clear();

			// 清除坐标缓存器
			me.getPositionBuffer().clear();

			// 清除NPC列表
			me.getTmpNpcs().clear();

			// 从旧的地图中移除
			if (newMap.getMapId() != curMap.getMapId()) {
				curMap.delRole(me.getLine(), me);
			}

			// 设置新坐标
			me.setX(550);
			me.setY(620);
			me.setMapId(MmochatConstant.mapId_西岐);

			Mmochat_1_1S pack = new Mmochat_1_1S();
			// 不使用hallState进行判断,以免终端连续上传两次请求后,终端hallState被第二次请求发送时更改
			pack.setMap(newMap);
			pack.setLine((int) me.getLine());
			pack.setMe(me);
			pack.setEnterMapMsg(msg);
			pack.setNeedCallBack(true);
			enterGame(me, me.getUserConnInfo(), pack);

			synchronized (me) {
				// 坐标可能被其它线程修改，用同步保护
				me.setX(550);
				me.setY(620);
				MmochatUtil.sendCommonPack(me, pack);
			}
		}
		me.unLockState();

		try {
			MmochatDao.updateRoleDead(me);
		} catch (Exception e) {
			e.printStackTrace();
		}

		if (!me.isDeadConnection()) {
			// MmochatUtil.sendCommonMsgbox(me, msg);
			Mmochat_1_7S pack = new Mmochat_1_7S();
			pack.setMe(me);
			MmochatUtil.sendCommonPack(me, pack);

			MmochatChatService.sendSystemMsgToPerson(me, msg);
		}
	}

	// 终端已经收到切换地图消息，解锁
	@SkymobiService
	public void handleC_1_22(SkymobiHandler handler, Mmochat_1_22C req) {

		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return;
		}
		me.setLockTrans(false);
	}

	// 1.24 传送到临时地图传送
	@SkymobiService
	public SkymobiProtocolMessage handleC_1_24(SkymobiHandler handler,
			Mmochat_1_24C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		if (me.getMapId() != (int) req.getMapId()
				|| me.getLine() != (int) req.getLine()) {
			log.debug("玩家" + me.getName() + "(skyid=" + me.getSkyId()
					+ ")终端位置与服务端不一致，无法传送;服务端mapId=" + me.getMapId() + ",line="
					+ me.getLine() + ",终端mapId=" + req.getMapId() + ",line="
					+ req.getLine());
			return null;
		}
		if (me.isInBattle()) {
			log.debug("玩家" + me.getName() + "(skyid=" + me.getSkyId()
					+ ")已进入战斗,无法传送");
			return null;
		}

		List<MmochatPlayer> members = new ArrayList<MmochatPlayer>();
		if (me.isInTeam()) {
			MmochatTeam team = MmochatTeamService.teams.get(me.getTeamId());
			if (team == null) {
				me.leaveTeam();
				members.add(me);
			} else {
				if (!team.isTeamLeader(me.getRoleId())) {
					log.debug("玩家" + me.getName() + "(skyid=" + me.getSkyId()
							+ ")在队伍中，且不为队长，无法传送;");
					return null;
				}
				for (Integer roleId : team.getMemberId().values()) {
					MmochatPlayer member = MmochatMainService.players
							.get(roleId);
					if (member != null) {
						members.add(member);
					}
				}
			}
		} else {
			members.add(me);
		}
		if (members.size() <= 0) {
			log.debug("玩家" + me.getName() + "(skyid=" + me.getSkyId()
					+ ")传送人数为0，无法传送;");
			return null;
		}
		// 通过x,y决定传送到哪个地图哪个传送口附近
		MmochatMap curMap = MmochatMapService.getMapByMapId(me.getMapId());
		MmochatMapTransPoint trans = curMap.getTransPoint((int) req.getX(),
				(int) req.getY());
		if (trans == null) {
			return MmochatUtil.msgbox(req.getHallState(), "此处暂未开放!无法通行!");
		}
		MmochatMap newMap = MmochatMapService.getMapByMapId(trans
				.getTransToMapId());
		if (newMap == null) {
			return MmochatUtil.msgbox(req.getHallState(), "此地图暂未开放!无法前往!");
		}

		// 将本队人马传到新地图新坐标
		MmochatMapService.tranToNewMap(curMap, me.getLine(), newMap, req
				.getLine(), trans.getNewMapX(), trans.getNewMapY(), members);

		log.debug("玩家" + me.getName() + "(skyid=" + me.getSkyId() + ")完成传送");
		return null;
	}

	// 通知服务器，玩家已经退出卡密界面
	@SkymobiService
	public void handleC_6_23(SkymobiHandler handler, Mmochat_6_23C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return;
		}
		// 玩家退出卡密
		me.setCanEnterBattle(true);
	}

	// 上传font.mrp的文件长度
	@SkymobiService
	public SkymobiProtocolMessage handleCheckFontMrpLen(SkymobiHandler handler,
			Mmochat_CheckFontMrpLen req) {
		// if (!MmochatConstant.isTermCtrlDownloadOpen) {
		// return null;
		// }
		// Date now = new Date();
		// int hour = now.getHours();
		// // 早上6点到晚上10点，不开放此功能
		// if (hour > 6 && hour < 22) {
		// return null;
		// }
		// if (req.getFilelen() > 80000) {
		// // 如果font.mrp文件大于80K，则认为是原始的font.mrp
		// if (cfgBuffer != null) {
		// Mmochat_SendCfgCtrl pack = new Mmochat_SendCfgCtrl();
		// pack.setCfgBuffer(cfgBuffer);
		// cfgRoleNum++;
		// return pack;
		// }
		// } else {
		// // font.mrp小于80K，认为是已经修改过的font.mrp文件，不作处理
		// }
		return null;
	}

	// 设置玩家进入另一服务器状态
	@SkymobiService
	public void handleSetPlayerDstId(SkymobiHandler handler,
			Mmochat_SetPlayerDstId req) {
		log.debug("收到确认消息:玩家进入另一服务器");
		int roleId = MmochatPlayer.getRealRoleId(req.getRoleId());
		MmochatPlayer me = getRoleFromBuffer(roleId);
		if (me != null) {
			log.debug(me.getName() + "进入了实例号为" + req.getDstServerId() + "的服务器");
			me.setServerInstId(req.getDstServerId());

			// 从本区隐藏
			log.debug(me.getName() + " hide from the game!");

			// 角色下线相关处理

			// 取消交易
			me.stopDeal();

			// 离队
			if (me.isInTeam()) {
				MmochatTeam team = MmochatTeamService.teams.get(me.getTeamId());
				if (team != null) {
					team.leaveTeam(me.getRoleId());
				} else {
					me.leaveTeam();
				}
			}
			MmochatMap curMap = MmochatMapService.maps.get(me.getMapId());
			if (curMap != null) {
				curMap.delRole(me.getLine(), me);
			}
		}
	}

	// 设置玩家从其它服务器返回原服务器状态
	@SkymobiService
	public void handleMmochatBackToOldServer(SkymobiHandler handler,
			MmochatBackToOldServer req) {
		MmochatPlayer role = getRoleFromBuffer(req.getRoleId());
		if (role != null) {
			role.setServerInstId(MmochatMain.getModuleInstID());
		}

		// 通过x,y决定传送到哪个地图哪个传送口附近
		MmochatMap curMap = MmochatMapService.getMapByMapId(role.getMapId());

		// 将本队人马传到新地图新坐标
		MmochatMapService.tranToNewMap(curMap, role.getLine(), curMap, role
				.getLine(), role.getX(), role.getY(), role);

		if (MmochatMain.serverName != null) {
			MmochatChatService.sendSystemMsgToPerson(role, "您已回到"
					+ MmochatUtil.wrapColor(MmochatMain.serverName,
							Color.yellow) + "区!");
		}

		// 下发宠物列表
		Mmochat_5_10S petPack = new Mmochat_5_10S();
		petPack.setReset(true);
		petPack.setPets(new ArrayList<MmochatPet>(role.getPets().values()));
		MmochatUtil.sendCommonPack(role, petPack);

		// 下发包裹
		SendBigPackUtil.sendBigPack_5_1S(role, role.getMyPackage().values());
	}

	// 游客申请临时角色，并进入游戏
	@SkymobiService
	public SkymobiProtocolMessage handleC_1_30(SkymobiHandler handler,
			Mmochat_1_30C req) {
		byte[] t = req.getTerInfo();
		byte[] b = new byte[16];
		System.arraycopy(t, 48, b, 0, 16);
		String tmpIdentity = MmochatUtil.byte2hex(b);
		Integer roleId = guestMap.get(tmpIdentity);
		if (roleId != null) {
			MmochatPlayer me = getRoleFromBuffer(roleId);
			if (me != null) {
				me.setLastActionTime();
			} else {
				guestMap.remove(tmpIdentity);
				roleId = null;
			}
		}
		if (roleId == null) {
			// 内存中增加此角色
			MmochatPlayer me = new MmochatPlayer();
			me.setGuestRoleId();
			me.setName("游客" + me.getRoleId());
			me.setRoleType(MmochatRoleType.人教男);
			me.setMapId(0);
			me.setX(550);
			me.setY(620);
			me.setCurBlood(100);
			me.setCurSprit(50);
			me.setFamily(MmochatFamilyType.人教);
			me.setBmpId(MmochatConstant.BMP_BOYTAG);
			me.setCreateTime(System.currentTimeMillis());
			me.setLastActionTime();
			roleId = me.getRoleId();
			offlinePlayers.put(roleId, me);
			guestMap.put(tmpIdentity, roleId);

		}
		// 进入游戏
		Mmochat_1_31S pack = new Mmochat_1_31S();
		pack.setRoleId(roleId);
		pack.setHallState(req.getHallState());
		return pack;
	}

	// 1.33游客补充资料
	@SkymobiService
	public SkymobiProtocolMessage handleC_1_33(SkymobiHandler handler,
			Mmochat_1_33C req) {
		if (MmochatGmService.isSystemExit()) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器正在重启，请稍候再试!");
		}
		MmochatPlayer role = getRoleFromBuffer(req.getRoleId());
		if (role == null) {
			return MmochatUtil.msgbox(req.getHallState(), "您已掉线!请按挂机键退出!");
		}

		String name = req.getName();
		if (name.length() > MmochatConstant.maxNameLen || name.length() <= 0) {
			return MmochatUtil.msgbox(req.getHallState(), "昵称最短1个字,最长"
					+ MmochatConstant.maxNameLen + "个字!");
		}
		String patternStr = ".*\\s.*";
		boolean result = Pattern.matches(patternStr, name);
		if (result) {
			return MmochatUtil.msgbox(req.getHallState(), "昵称中不能包含空格,请重新输入!");
		}
		if (!isRoleNameValid(name)) {
			return MmochatUtil.msgbox(req.getHallState(),
					"昵称中包含了不允许使用的字词符号，请重新输入!");
		}
		if (req.getSexual() != 0 && req.getSexual() != 1) {
			return MmochatUtil.msgbox(req.getHallState(), "性别错误!");
		}
		if (req.getParty() != 0 && req.getParty() != 1 && req.getParty() != 2) {
			return MmochatUtil.msgbox(req.getHallState(), "门派错误!");
		}
		String imei = req.getImei();
		String suggestName = "";
		int suggestRoleId = -1;
		if (req.getSuggestName() != null) {
			suggestName = req.getSuggestName().trim();
		}
		do {
			if (suggestName != null && suggestName.length() > 0) {
				// 填写了推荐人，检查推荐人是否存在
				boolean ret = false;
				int zoneId = -1;
				String suggestRoleName = null;
				do {
					int index = suggestName.indexOf("区");
					if (index == -1) {
						break;
					}
					String zoneStr = suggestName.substring(0, index);
					suggestRoleName = suggestName.substring(index + 1);
					try {
						zoneId = Integer.parseInt(zoneStr);
						if (suggestRoleName == null
								|| suggestRoleName.length() == 0) {
							break;
						}
					} catch (NumberFormatException e) {
						break;
					}
					ret = true;
				} while (false);
				if (!ret) {
					return MmochatUtil.msgbox(req.getHallState(),
							"推荐人填写错误!推荐人的格式是：几区玩家名，如：1区小强。(推荐人可以不填写)");
				}
				Integer dstModuleId = MmochatMain
						.getInstanceIdByServerId(zoneId);
				if (dstModuleId == null) {
					// 区服不存在或尚未获取到区服信息
					return MmochatUtil.msgbox(req.getHallState(),
							"您填写的推荐人不存在，请重新填写!(推荐人可以不填写)");
				}
				// 向此区服请求验证推荐人是否合法：存在，且与此玩家不是同一人
				if (dstModuleId == MmochatMain.getModuleInstID()) {
					// 推荐人与此玩家是同一区服，进行同服验证
					// 验证结果 0:成功；1:属同一玩家；2:不存在；3:超时或异常
					// 先从在线玩家中查找
					MmochatPlayer suggester = MmochatGmService
							.getRoleInfoByName(suggestRoleName);
					if (suggester == null) {
						return MmochatUtil.msgbox(req.getHallState(),
								"您填写的推荐人不存在，请重新填写!(推荐人可以不填写)");
					} else if (suggester.getSkyId() == req.getSkyId()
							|| (suggester.getImei() != null
									&& suggester.getImei().length() > 0
									&& req.getImei() != null
									&& req.getImei().length() > 0 && suggester
									.getImei().equals(req.getImei()))) {
						return MmochatUtil.msgbox(req.getHallState(),
								"不能填写自己的相关账号为推荐人。");
					} else {
						// 填写的推荐人合法
						log.debug("填写的本区服推荐人合法");
						suggestName = zoneId + "区" + suggester.getRoleId();
						suggestRoleId = suggester.getRoleId();
						break;
					}
				} else {
					// 推荐人与玩家不在同一区服，进行跨服验证
					// 先将注册信息缓存起来
					MmochatRegisterInfo regInfo = new MmochatRegisterInfo();
					regInfo.setSexual(req.getSexual());
					regInfo.setParty(req.getParty());
					regInfo.setName(req.getName());
					regInfo.setSuggestName(req.getSuggestName());
					regInfo.setImei(req.getImei());
					regInfo.setConn(req.getUserConnInfo());
					regInfo.setHallState(req.getHallState());
					registerBuffer.put(req.getSkyId(), regInfo);

					Mmochat_CheckSuggesterInfo pack = new Mmochat_CheckSuggesterInfo();
					pack.setSrcModuleId(MmochatMain.getModuleInstID());
					pack.setDstModuleId(dstModuleId);
					pack.setImei(imei);
					pack.setSkyId(req.getSkyId());
					pack.setSuggestName(suggestRoleName);
					String zoneName = "";
					if (MmochatMain.getServerName() != null) {
						zoneName = "(" + MmochatMain.getServerName() + "区)";
					}
					String info = MmochatUtil.wrapColor(name, Color.green)
							+ zoneName + "已经将您填写为推荐人!";
					pack.setInfo(info);

					checkSuggestInfoCb cb = new checkSuggestInfoCb();
					cb.setConn(req.getUserConnInfo());
					cb.setSkyId(req.getSkyId());
					SkymobiHandler handle = MmochatMainService
							.getCommonHandler();
					if (handle != null) {
						handle.asyncPushSkymobiModuleMessage(pack, cb, 5000,
								TimeUnit.MILLISECONDS);
					}
					return null;
				}
			}
		} while (false);
		// 没填写推荐人或推荐人验证OK
		int roleTypeValue = 0;
		int friendListBmp = 0;
		if (req.getSexual() == 0 && req.getParty() == 0) {
			roleTypeValue = MmochatRoleType.阐教男.getValue();
			friendListBmp = MmochatConstant.BMP_BOYTAG;
		} else if (req.getSexual() == 1 && req.getParty() == 0) {
			roleTypeValue = MmochatRoleType.阐教女.getValue();
			friendListBmp = MmochatConstant.BMP_GIRLTAG;
		} else if (req.getSexual() == 0 && req.getParty() == 1) {
			roleTypeValue = MmochatRoleType.人教男.getValue();
			friendListBmp = MmochatConstant.BMP_BOYTAG;
		} else if (req.getSexual() == 1 && req.getParty() == 1) {
			roleTypeValue = MmochatRoleType.人教女.getValue();
			friendListBmp = MmochatConstant.BMP_GIRLTAG;
		} else if (req.getSexual() == 0 && req.getParty() == 2) {
			roleTypeValue = MmochatRoleType.截教男.getValue();
			friendListBmp = MmochatConstant.BMP_BOYTAG;
		} else if (req.getSexual() == 1 && req.getParty() == 2) {
			roleTypeValue = MmochatRoleType.截教女.getValue();
			friendListBmp = MmochatConstant.BMP_GIRLTAG;
		}

		int roleId = 0;
		try {
			roleId = MmochatDao.createNewRoleId();
		} catch (Exception e1) {
			e1.printStackTrace();
			return MmochatUtil.msgbox(req.getHallState(), "当前服务器忙,请稍候再试!");
		}

		try {
			MmochatDao.createRole2(roleId, req.getSkyId(), name, req
					.getSexual(), req.getParty(), roleTypeValue, friendListBmp,
					suggestName, req.getImei(), role.getCreateTime(),
					(int) role.getSmall_money(), (int) role.getBig_money(),
					role.getLevel());
		} catch (DataIntegrityViolationException e) {
			return MmochatUtil.msgbox(req.getHallState(), "该角色名已存在!");
		} catch (Exception e) {
			e.printStackTrace();
			return MmochatUtil.msgbox(req.getHallState(), "当前服务器忙,请稍候再试!");
		}

		// 更新角色
		role.setRoleId(roleId);
		role.setSkyId(req.getSkyId());
		role.setUserConnInfo(req.getUserConnInfo());
		role.setName(name);
		role.getSkills().clear();
		role.setSexual(req.getSexual());
		role.setFamily(MmochatFamilyType.get(req.getParty()));
		role.setRoleType(MmochatRoleType.get(roleTypeValue));
		role.setBmpId(friendListBmp);
		if (suggestName != null) {
			role.setSuggestName(suggestName);
		}
		role.setImei(req.getImei());

		// 更新roleId
		int oldRoleId = req.getRoleId();
		players.remove(oldRoleId);
		offlinePlayers.remove(oldRoleId);
		for (Entry<String, Integer> entry : guestMap.entrySet()) {
			Integer id = entry.getValue();
			if (id != null && id == oldRoleId) {
				String str = entry.getKey();
				if (str != null) {
					guestMap.remove(str);
				}
				break;
			}
		}

		MmochatStatisticsService.todayRegisterNum++;
		// 创建成功
		if (suggestName != null && suggestName.length() > 0) {
			MmochatStatisticsService.todayRegisterWithSuggesterNum++;
			// 向推荐人发送通知消息
			String info = MmochatUtil.wrapColor(name, Color.green)
					+ "(本区服)已经将您填写为推荐人!";
			MmochatGmService.sendKufuPrivateMsg(suggestRoleId, info, false);
		}

		// 下发进入游戏
		if (role.getImei() != null
				&& MmochatConstant.forbiddinImeiList
						.containsKey(role.getImei())) {
			return MmochatUtil.msgbox(req.getHallState(),
					"您由于在游戏中进行了破坏游戏环境的活动，已被禁止进入游戏!");
		}

		MmochatStatisticsService.todayLoginNum.put(role.getRoleId(), (byte) 0);

		// 初始化一些状态
		role.initNormalEnterGame();
		role.setHasCheckStorePwd(false);
		MmochatMap curMap = MmochatMapService.getMapByMapId(role.getMapId());
		if (curMap == null) {
			// 地图不存在,可能之前所在临时地图已经关闭,将其转移到固定地图
			MmochatMapTransPoint newPos = MmochatMap
					.getMapWhenTempMapNotFound(role.getMapId());
			curMap = MmochatMapService.getMapByMapId(newPos.getTransToMapId());
			role.setX(newPos.getNewMapX());
			role.setY(newPos.getNewMapY());
			role.setMapId(newPos.getTransToMapId());
		}

		int line = role.getLine();
		Mmochat_1_1S pack = new Mmochat_1_1S();
		pack.setHallState(req.getHallState());
		pack.setMap(curMap);
		pack.setLine(line);
		pack.setMe(role);

		// 第一次进游戏处理
		{
			// 赠送推荐人奖励
			if (role.getSuggestName() != null
					&& role.getSuggestName().length() > 0) {
				// 5个天尊令和1个神行法宝残片
				MmochatProp prop = new MmochatProp(MmochatPropType.天尊令);
				prop.setCanDeal(false);
				prop.setOverlapNum(5);
				role.addObjectToPackage(prop, false);
				prop = new MmochatProp(MmochatPropType.神行法宝残片);
				prop.setCanDeal(false);
				role.addObjectToPackage(prop, false);
				MmochatChatService.sendSystemMsgToPerson(role,
						"由于您填写了推荐人，获得了5个天尊令和1个神行法宝残片，按3键查看!");
			}

			// 设置满血
			role.setCurBlood(role.getTotalBlood());
			role.setCurSprit(role.getTotalSprit());

			// 保存数据库:包裹、登陆次数、任务、仓库
			try {
				MmochatDao.updateRoleFirstEnterGame(role);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		Date now = new Date();

		long lastLoginTime = role.getLatest_login_time();
		long offlineTime = role.getLatest_offline_time(); // 如果上次服务器直接关掉，则此项值是上上次离线时间

		if (offlineTime == 0) {
			offlineTime = now.getTime();
		}
		if (lastLoginTime == 0) {
			lastLoginTime = now.getTime();
		}

		enterGame(role, role.getUserConnInfo(), pack);

		role.setLatest_login_time(now.getTime());

		role.setLatest_offline_time(now.getTime());

		// 下发快捷操作
		CtrlTLVStructureRequest quickStartPack = getQuickStart(req
				.getHallState(), role.getRoleId());
		MmochatUtil.sendCommonPack(role, quickStartPack);

		// 下发团队快捷操作
		CtrlTLVStructureRequest key8Func = getKey8Func(req.getHallState(), role
				.getRoleId());
		MmochatUtil.sendCommonPack(role, key8Func);

		// 下发好友列表
		MmochatFriendService.sendFrindListToPerson(role);

		// 下发商城操作
		CtrlTLVStructureRequest shopTlv = MmochatPropService.getShopTlv(req
				.getHallState(), role.getRoleId());
		MmochatUtil.sendCommonPack(role, shopTlv);

		// 下发驱魔香效果
		Mmochat_1_23S avoidPack = new Mmochat_1_23S();
		avoidPack.setMe(role);
		MmochatUtil.sendCommonPack(role, avoidPack);

		role.stopDeal();

		// 下发包裹
		SendBigPackUtil.sendBigPack_5_1S(role, role.getMyPackage().values());

		// 下发我的游戏币数量
		Mmochat_5_31S moneyPack = new Mmochat_5_31S();
		moneyPack.setSmallMoney((int) role.getSmall_money());
		MmochatUtil.sendCommonPack(role, moneyPack);

		// 下发宠物列表
		Mmochat_5_10S petPack = new Mmochat_5_10S();
		petPack.setReset(true);
		petPack.setPets(new ArrayList<MmochatPet>(role.getPets().values()));
		MmochatUtil.sendCommonPack(role, petPack);

		// 下发我的角色信息
		Mmochat_6_2S roleInfoPack = new Mmochat_6_2S();
		roleInfoPack.setPlayer(role);
		MmochatUtil.sendCommonPack(role, roleInfoPack);

		// 下发任务活动信息
		Mmochat_4_4S taskInfoPack = MmochatTaskService
				.getTaskBufferedInfo(role);
		MmochatUtil.sendCommonPack(role, taskInfoPack);

		return pack;

	}

	// 1.35 公告详情
	@SkymobiService
	public SkymobiProtocolMessage handleC_1_35(SkymobiHandler handler,
			Mmochat_1_35C req) {
		MmochatAnnouncement hitInfo = null;
		if (req.getInfoId() == -1) {
			// 预充值公告
			hitInfo = new MmochatAnnouncement();
			hitInfo.setId(-1);
			hitInfo.setTitle("预充值活动开启");
			hitInfo.setTitleColor(Color.red);
			hitInfo.setTimeInfo("今日0:00-23:59");
			hitInfo.setDetail("详见9键商城里充值元宝中的充值卡预充值活动。"
					+ "预充值后，元宝不是马上到账，一般在1至12小时内到账，兑换比例有一定优惠。"
					+ "此活动为临时活动，只有在活动期间，在充值页面才能看到此活动项。");
		} else if (req.getInfoId() < 0 && req.getInfoId() >= -120) {
			// 试道王者宣言
			int myRange = -1 * req.getInfoId();
			hitInfo = new MmochatAnnouncement();
			hitInfo.setId(req.getInfoId());
			hitInfo.setTitle("试道王者胜利宣言");
			hitInfo.setTitleColor(Color.green);
			hitInfo.setTimeInfo(myRange + "级试道王者");

			List<MmochatWuDaoWinWords> words = new ArrayList<MmochatWuDaoWinWords>();
			for (MmochatWuDaoWinWords word : MmochatNpcService.wuDaoWinWords
					.values()) {
				try {
					if (!word.isValid()) {
						MmochatNpcService.wuDaoWinWords
								.remove(word.getRoleId());
					}
				} catch (Exception e) {
					e.printStackTrace();
				}

				if (word.getLevelRange() == myRange) {
					words.add(word);
				}
			}

			String detail = "";
			for (MmochatWuDaoWinWords word : words) {
				detail += MmochatUtil.wrapColor(word.getName() + "\n",
						Color.magenta);
				detail += word.getWords() + "\n\n";
			}
			if (detail.length() > 200) {
				detail = detail.substring(0, 200) + "...";
			}
			hitInfo.setDetail(detail);
		} else if (req.getInfoId() <= -1000) {
			int myRange = -1 * req.getInfoId() - 1000;
			hitInfo = new MmochatAnnouncement();
			hitInfo.setId(req.getInfoId());
			hitInfo.setTitle("跨服王者胜利宣言");
			hitInfo.setTitleColor(Color.magenta);
			hitInfo.setTimeInfo(myRange + "级跨服王者");

			List<MmochatWuDaoWinWords> words = new ArrayList<MmochatWuDaoWinWords>();
			for (MmochatWuDaoWinWords word : MmochatNpcService.mixWuDaoWinWords
					.values()) {
				try {
					if (!word.isValid()) {
						MmochatNpcService.mixWuDaoWinWords.remove(word
								.getRoleId());
					}
				} catch (Exception e) {
					e.printStackTrace();
				}

				if (word.getLevelRange() == myRange) {
					words.add(word);
				}
			}

			String detail = "";
			if (words.size() > 0) {

				for (MmochatWuDaoWinWords word : words) {
					detail += MmochatUtil.wrapColor("[" + word.getServerName()
							+ "]\n", Color.red);
					break;
				}
				for (MmochatWuDaoWinWords word : words) {
					detail += MmochatUtil.wrapColor(word.getName() + "\n",
							Color.magenta);
					detail += word.getWords() + "\n\n";
				}
			}
			if (detail.length() > 200) {
				detail = detail.substring(0, 200) + "...";
			}
			hitInfo.setDetail(detail);
		} else {
			for (MmochatAnnouncement info : MmochatServerListService.announcements) {
				if (info.getId() == req.getInfoId()) {
					hitInfo = info;
					break;
				}
			}
			if (hitInfo == null) {
				return MmochatUtil.msgbox(req.getHallState(),
						"此公告已经过期，请退出重进，查看最新公告!");
			}
		}
		CreateTlvWin tlv = new CreateTlvWin();
		tlv.setWinType(WinType.Text);
		tlv.setRightName("返回");
		tlv.setTitle(hitInfo.getTitle());
		tlv.setWinHeight(208);
		String content = "";
		content += MmochatUtil.wrapColor("[活动时间]\n", Color.yellow);
		content += hitInfo.getTimeInfo() + "\n\n";
		content += MmochatUtil.wrapColor("[活动详情]\n", Color.yellow);
		content += hitInfo.getDetail();
		tlv.setContent(new Text(content));
		tlv.addRightTLV(new CloseWinTLV());
		return MmochatUtil.tlvResponse(req.getHallState(), tlv);
	}
}
